Flex 4 two-way data binding on properties of non-matching types

Is there really no simple way to perform two-way data binding on properties of non-matching types? In the example below I was trying to bind two properties to each other: one of type String (text property from s:TextInput) and the other of type Number (bar property from Foo)

package com.example
{
    public class Foo
    {
        [Bindable] public var bar:Number;
    }
}

<?xml version="1.0" encoding="utf-8"?>
<s:Application
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"

    xmlns:ex="com.example.*"
>
    <fx:Declarations>
        <ex:Foo id="foo" />
    </fx:Declarations>
    <s:TextInput text="@{foo.bar}" /><!-- error at this line -->
</s:Application>

Attempting to compile this code results in the following error:

1067: Implicit coercion of a value of type String to an unrelated type Number.

I understand why the error happens, but I was wondering if I'm simply ignorant of something (perhaps some sort of Flex 4 metadata) that would allow for an attempt at conversion between the two types and throwing a run-time error if such a conversion fails...

Answers


The only thing I was able to come up with is to change the type of property bar in Foo to * (star is a wild card, which prevents type checking at compile time). But I'd still very much like to know if there's a way to keep the type...


I ended up using a data renderer for my object, which is blind to the data type. So, I guess the only solution is to up-cast to an Object or * and call methods that you "know" are there. Although doing this may create run-time errors that would normally have been caught at compile time, I see no better solution.


Need Your Help

not able to install grails 2.0.0.RC1

grails grails-2.0

I upgraded my grails to v 2.0, set grails_home to new grails location and updated the path variable,

Ruby 1.9.3 Is Not Installing (Mac OS X Lion)

ruby

Here's my current version of Ruby:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.