I'm not sure I fully understand what you mean, Alex.  In my button click
code, I modify the properties.  Could you clarify that?  Do you also mind
jotting in a comment on the but reports I entered to just confirm that you
were able to reproduce it in 4.0?

Does this mean "as" should be avoided and only used in cases where the
ClassName() syntax will wind up doing more than just type coercion (like
Array) for now?

Thanks.

On Wed, May 13, 2009 at 1:24 AM, Alex Harui <aha...@adobe.com> wrote:

>
>
>  I was able to repro in 4.0 beta builds.  It looks like the parser simply
> can’t handle the “as” syntax.  That means that it the binding may not
> respond to changes to some kinds of changes because it isn’t watching the
> right events.  It might work for these purposes as in a renderer the entire
> data object changes, but if you found a way to just modify the one property
> it probably won’t pick that up.
>
>
>
> Alex Harui
>
> Flex SDK Developer
>
> Adobe Systems Inc. <http://www.adobe.com/>
>
> Blog: http://blogs.adobe.com/aharui
>
>
>
> *From:* flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] *On
> Behalf Of *valdhor
> *Sent:* Tuesday, May 12, 2009 1:42 PM
> *To:* flexcoders@yahoogroups.com
> *Subject:* [flexcoders] Re: using "as" breaks data binding?
>
>
>
>
>
>
>  I think I may have an answer. I broke down the code into its constituent
> pieces and I now have a theory.
>
> My theory:
> When you use (data as TestObject).b, you are actually trying to bind to the
> data property of the item renderer. As this is not a bindable property, you
> get the error. When you use the cast: TestObject(data).a, you are now
> binding to TestObject which does have bindable properties.
>
> Have a look at the following code...
>
> TestObject.as
> package
> {
>   public class TestObject
>   {
>     [Bindable] public var item1:uint = 2;
>     [Bindable] public var item2:uint = 3;
>     [Bindable] public var item3:uint = 1;
>   }
> }
>
> HBoxItemRenderer.as
> <?xml version="1.0" encoding="utf-8"?>
> <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml";>
>     <mx:Script>
> &! nbsp;       <![CDATA[
>
>             [Bindable] private var theTestObject:TestObject;
>
>             override public function set data(value:Object):void
>             {
>                 super.data = value;
>                 if(value != null)
>                 {
>                     theTestObject = data as TestObject;
>                 }
>             }
>         ]]>    </mx:Script>
>    ! <mx: Label text="{theTestObject.item1}"/>
>     <mx:Label text="{theTestObject.item2}"/>
>     <mx:Label text="{theTestObject.item3}"/>
> </mx:HBox>
>
> DataBindingTest.mxml
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="absolute">
>   <mx:Script>
>     <![CDATA[
>       import mx.collections.ArrayCollection;
>
>       [Bindable] private var d:ArrayCollection = new ArrayCollection([
>         new TestObject,
>         new TestObject,
>         new TestObject
>       ]);
>     ]]>
>   </mx:Script>
>   <mx:List dataProvider="{d}! " itemRenderer="HBoxItemRenderer" />
>   <mx:Button click="for each(var o:TestObject in d) { o.item1++; o.item2++;
> o.item3++ }"/>
> </mx:Application>
>
>
> If anyone thinks my theory is incorrect, please chime in.
>
>
> HTH
>
>
>
> Steve
>
>
> --- In flexcoders@yahoogroups.com, Pan Troglodytes <chimpathe...@...>
> wrote:
> >
> > Well, I entered the two related issues as:
> >
> > https://bugs.adobe.com/jira/browse/SDK-21100
> > https://bugs.adobe.com/jira/browse/SDK-21101
> >
> > Maybe someone at Adobe can manage to reproduce them. I'm not really sure
> > how much harm is being done, since the code appears to work right in the
> > end. But someone weird and unexpected seems to be going on under the
> hood.
> >
> >
> > On Tue, May 12, 2009 at 2:39 PM, Pan Troglodytes chimpathe...@...wrote:
> >
> >! ; > Thanks for giving me some confirmation. Now if we coul! d just f
> igure out
> > > what Alex/Adobe need to do to replicate our tests.
> > >
> > > The reason it doesn't give a warning on "y" is due to what I referenced
> > > (perhaps unclearly) above. Notice in the warning it tells you it can't
> bind
> > > to that value on the *itemRenderer *(GenericTest_inlineComponent1 in my
> > > test), not on the *TestObject* instance. The itemRenderer has an x and
> y
> > > object, so that's why it doesn't complain. It doesn't make any sense
> that
> > > it should be looking at binding to the itemRenderer instead of the
> > > TestObject instance, though.
> > >
> > >
> > > On Tue, May 12, 2009 at 12:24 PM, valdhor valdhorli...@...wrote:
> > >
> > >>
> > >>
> > >> Jason
> > >>
> > >> As a sanity check I tried it and I get the exact same error. I am
> using
> > >> Flex SDK 3.3.0 and Flash Player WIN 9,! 0,159,0 Debug.
> > >>
> > >> Strangely enough, changing b to y fixes it and the error goes away.
> Other
> > >> variable identifiers I have tried (Very small sample) gives the error
> as
> > >> well.
> > >>
> > >> It's got me beat.
> > >>
> > >> Why would the posted code give an error at all?
> > >>
> > >> Why would y work and everything else not?
> > >>
> > >>
> > >> --- In flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>, Pan
> > >> Troglodytes chimpathetic@ wrote:
> > >> >
> > >> > I wonder if I wasn't clear enough on this - these are run-time
> warnings
> > >> that
> > >> > output to the console. You don't get those?
> > >> >
> > >> >
> > >> > On Mon, May 11, 2009 at 5:27 PM, Alex Harui aharui@ wrote:
> > >> >
> &! gt; >> > >
> > >> > >
> > >! > > ; > I didn't get any warnings like you did so I couldn't
> investigate
> > >> further.
> > >> > >
> > >> > >
> > >> > >
> > >> > > Alex Harui
> > >> > >
> > >> > > Flex SDK Developer
> > >> > >
> > >> > > Adobe Systems Inc. <http://www.adobe.com/>
> > >> > >
> > >> > > Blog: http://blogs.adobe.com/aharui
> > >> > >
> > >> > >
> > >> > >
> > >> > > *From:* flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com
> >[mailto:
> > >> flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>] *On
> > >> > > Behalf Of *Pan Troglodytes
> > >> > > *Sent:* Saturday, May 09, 2009 10:38 PM
> > >> > > *To:* flexcoders@yahoogroups.com <flexcod! ers%40yahoogroups.com>
> > >> > > *Subject:* Re: [flexcoders] using "as" breaks data binding?
> > >> > >
> > >> > >
> > >> > >
> > >> > >
> > >> > >
> > >> > >
> > >> > > 3.3.0. I also get it with 4.0.0.6137. Just downloaded and got it
> in
> > >> > > 6772, too. I'm using player version 10,0,12,36. Do you need to
> know
> > >> > > anything about my Flex Builder version? Let me know anything else
> I
> > >> can
> > >> > > provide.
> > >> > >
> > >> > > When you say you don't get it with the soon-to-be 3.4, what
> exactly do
> > >> you
> > >> > > mean? You just don't get the run-time warning? Did you track down
> why
> > >> it
> > >> > > would be okay with "x" and see if that's still doing whatever
> weird
> > ! >> thing it
> > >> > > is in 3.4?
> >! ; >&g t; > >
> > >> > > On Sat, May 9, 2009 at 4:11 PM, Alex Harui aharui@ wrote:
> > >> > >
> > >> > >
> > >> > >
> > >> > > Which version of Flex? I don't get it on the latest builds that
> will
> > >> ship
> > >> > > as 3.4
> > >> > >
> > >> > >
> > >> > >
> > >> > > Alex Harui
> > >> > >
> > >> > > Flex SDK Developer
> > >> > >
> > >> > > Adobe Systems Inc. <http://www.adobe.com/>
> > >>
> > >> > >
> > >> > > Blog: http://blogs.adobe.com/aharui
> > >> > >
> > >> > >
> > >> > >
> > >> > > *From:* flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com
> >[mailto:
> > >> flexcod...@yahoogroup! s.com <flexcoders%40yahoogroups.com>] *On
>
> > >> > > Behalf Of *Pan Troglodytes
> > >> > > *Sent:* Friday, May 08, 2009 11:06 PM
> > >> > > *To:* flexcoders
> > >> > > *Subject:* [flexcoders] using "as" breaks data binding?
> > >> > >
> > >> > >
> > >> > >
> > >> > >
> > >> > >
> > >> > > I've run across some peculiar behavior and I am trying to figure
> out
> > >> if I
> > >> > > should report it and if so, how exactly to explain it. Given these
> two
> > >> bits
> > >> > > of code:
> > >> > >
> > >> > > *TestObject.as:*
> > >> > > package
> > >> > > {
> > >> > > public class TestObject
> > >> > > {
> > >> > > [Bindable] public var a:uint = 2;!
> > >> > > [Bindable] public var b:uint = 3;> >> > > [Bindable] public var
> x:uint = 1;
> > >> > > }
> > >> > > }
> > >> > >
> > >> > > *Main Application:*
> > >> > > <?xml version="1.0" encoding="utf-8"?>
> > >> > > <Application
> > >> > > xmlns="http://www.adobe.com/2006/mxml";
> > >> > > >
> > >> > > <Script>
> > >> > > <![CDATA[
> > >> > > import mx.collections.ArrayCollection;
> > >> > > [Bindable] public var d:ArrayCollection = new ArrayCollection([
> > >> > > new TestObject,
> > >> > > new TestObject,
> > >> > > new TestObject
> > >> > > ]);
> > >> > > ]]>
> > >> > > </Script>
> > >> > > <List dataProvider="{d}">
> > >> ! > > <itemRenderer>
> > >> > > <Component>
> > >> > > <HBox>
> > >> > > <Label text="{TestObject(data).a}"/>
> > >> > > <Label text="{(data as TestObject).b}"/>
> > >> > > <Label text="{(data as TestObject).x}"/>
> > >> > > </HBox>
> > >> > > </Component>
> > >> > > </itemRenderer>
> > >> > > </List>
> > >> > > <Button click="for each (var o:TestObject in d) { o.x++; o.a++;
> o.b++
> > >> > > }"/>
> > >> > > </Application>
> > >> > >
> > >> > > If you run this application, you get the following warnings:
> > >> > > warning: unable to bind to property 'b' on class
> > >> > > 'GenericTest_inlineComponent1'!
> > >> > > warning: unable to bind to propert! y 'b' on class
> > >> > > 'GenericTest_inlineComponent1'
> > >> > > warning: unable to bind to property 'b' on class
> > >> > > 'GenericTest_inlineComponent1'
> > >> > > warning: unable to bind to property 'b' on class
> > >> > > 'GenericTest_inlineComponent1'
> > >> > > warning: unable to bind to property 'b' on class
> > >> > > 'GenericTest_inlineComponent1'
> > >> > > warning: unable to bind to property 'b' on class
> > >> > > 'GenericTest_inlineComponent1'
> > >> > >
> > >> > > There's a couple of things that stand out here. First, it doesn't
> > >> complain
> > >> > > about properties "x" or "a". The reason it doesn't complain about
> > >> property
> > >> > > "a" is that I used "TestObject(data).a" i! nstead of "(data as
> > >> > > TestObject).a". If you change it to the other way around, you will
> get
> > >> a
> > >> > > warning on "a" as well. I find this rather bizarre, as I thought
> there
> > >> was
> > >> > > no functional difference to the two, other than "as" returning
> null if
> > >> the
> > >> > > object wasn't of the appropriate type rather than just erroring
> out
> > >> like
> > >> > > straight type coercion does. But type coercion/as are very (ahem)
> > >> "lightly"
> > >> > > documented so I admit I don't know a lot. But I don't think it's
> > >> because of
> > >> > > the null problem, since you can replace it with
> "TestObject(null).b"
> > >> and it
> > >> > > stops giving the warning.
> > >> > >
> > >> > > The second weird th! ing is that it doesn't complain about "x"
> when
> > >>! ; using< br>> >> > > "(data as TestObject).x" like it does with a. As
> you can see, it's
> > >> claiming
> > >> > > this error is on GenericTest_inlineComponent1. This is significant
> > >> > > because it appears that it's instead doing some binding to the "x"
> > >> property
> > >> > > on the item renderer, which is *very* odd. You can try this
> yourself
> > >> by
> > >> > > changing "x" to other strings. Ones where there is a property of
> HBox
> > >> named
> > >> > > the same thing won't give you a warning. Others will.
> > >> > >
> > >> > > Yet for all this griping, it seems the data binding IS working. If
> you
> > >> > > click on the button, you'll see all the labels in the list change
> as
> > >> the
> > >> > > data is being changed.
> > >> > >
> &! gt; >> > > So, anyone want to shed some light on these two behaviors?
> > >> > >
> > >> > > --
> > >> > > Jason
> > >> > >
> > >> > >
> > >> > >
> > >> > >
> > >> > > --
> > >> > > Jason
> > >> > >
> > >> > >
> > >> > >
> > >> >
> > >> >
> > >> >
> > >> > --
> > >> > Jason
> > >> >
> > >>
> > >>
> > >>
> > >
> > >
> > >
> > > --
> > > Jason
> > >
> >
> >
> >
> > --
> > Jason
> >
>
>   
>



-- 
Jason

Reply via email to