Reputation: 147
I have:
class A: with a property "data:ArrayCollection". It's my data source (data provider) and has bitmaps.
class B: has an instance of A (called "Ainst") and calls the following method: C.init( Ainst.data). To pass the data provider to Object C.
class C: has a reference of the data provider "data" (because of "init" method). It shows the arrayCollection into Images as: Image.source = data.getItemAt(0).
But C never updates its images, that is, data binding doesn't work with this scheme. I've put [Bindable] meta-tag in all properties and even classes.
class A:
public class A{ [Bindable]public var data:ArrayCollection; }
class B:
public class B{ [Bindable]public var Ainst:A; public var Cinst:C; public function init(){ Cinst = new C(); Cinst.init(A.data) } }
class C: An image menu with 3 items (bitmaps)
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:local="*"
horizontalAlign="center"
paddingTop="10"
paddingBottom="10"
gap="10">
<fx:Script>
<![CDATA[
[Bindable] public var _images:ArrayCollection;
public function init( images:ArrayCollection ):void{
_images = images;
}
]]>
</fx:Script>
<ms:Image id="PreviousButton" smoothBitmapContent="true" width="55" height="55" source="@Embed(source='/../figures/upArrow.png')"/>
<ms:Image id="TopItem" smoothBitmapContent="true" maintainAspectRatio="true" x="12.5" source="{_images.getItemAt(0)}" />
<ms:Image id="MiddleItem" smoothBitmapContent="true" maintainAspectRatio="true" x="12.5" source="{_images.getItemAt(1)}"/>
<ms:Image id="BottomItem" smoothBitmapContent="true" maintainAspectRatio="true" x="12.5" source="{_images.getItemAt(3)}"/><!-- getItemAt(2).image -->
<ms:Image id="NextButton" smoothBitmapContent="true" width="55" height="55" source="@Embed(source='/../figures/downArrow.png')"/>
</s:VGroup>
Any thought? Thanks.
Upvotes: 0
Views: 769
Reputation: 14221
Take a look at your class A
:
public class A{
[Bindable]
public var data:ArrayCollection;
}
The property data
here isn't static. So it is related to instance of A
but not A
itself. Now take a look at constructor of B
:
public function init(){
Cinst = new C();
Cinst.init(A.data);
}
And its field declaration:
[Bindable]
public var Ainst:A;
As you can see in a line
Cinst.init(A.data);
you're referring data
as a static property. You should use:
public function init(){
Cinst = new C();
Cinst.init(Ainst.data);
}
instead.
And please keep ActionScript naming and coding conventions. Place statements in a separate lines and start identifiers with lowercase letter. It allows to read your code easier.
Upvotes: 0
Reputation: 1251
Your problem is that the function getItemAt (_images.getItemAt(0)) is NOT Bindable.
Upvotes: 1