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 [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Pan Troglodytes
Sent: Saturday, May 09, 2009 10:38 PM
To: flexcoders@yahoogroups.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?

On Sat, May 9, 2009 at 4:11 PM, Alex Harui 
<aha...@adobe.com<mailto:aha...@adobe.com>> 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<mailto:flexcoders@yahoogroups.com> 
[mailto:flexcoders@yahoogroups.com<mailto:flexcoders@yahoogroups.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 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'
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" instead 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 thing is that it doesn't complain about "x" when using "(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.

So, anyone want to shed some light on these two behaviors?

--
Jason



--
Jason

Reply via email to