0 Replies Latest reply on Jun 25, 2010 10:53 AM by emtorce

    Flex 4 + Binding + Casting

    emtorce

      Hey all!

       

      I've tried to find an answer to this that works in Flash Builder in the forums, but haven't yet - please feel free to redirect me if this is a repost!  =)

       

      My question is about casting within a binding tag.  I was having problems casting from "Object" to a "Person" object (created in-house).  Per threads about this written in 2007, this seems perfectly acceptable.  Not so to my Flash Builder compiler.  As a most basic test, I tried this:

       

      [Bindable] public var test1:Object;

      [Bindable] public var test2:Object;

       

      then bound like this:

       

      <fx:Binding source="test1" destination="test2" twoWay="true"/>

       

      this obviously worked.  I then tried something I imagined would be redundant, and copied the format of the cast I had tried to do earler between Object and Person (that had failed):

       

      <fx:Binding source="test1" destination="Object(test2)" twoWay="true"/>

       

      This failed with an 1105 error :Target of assignment must be a reference value.  Swapping the cast over to the source side instead of the destination side produced the same error.  Does this mean that the cast creates a new, immutable object that is unable to be referenced in a bind?

       

      If so, what methodology/best practices should be used to go around this problem?  If test2's class was changed to be "Person" rather than object, and I knew that test1 was an object that was originally created as a Person object, how can I ever bind the two?

       

      Thanks in advance for any help!  =)

       

      -Emily