I have a component being called within a repeater. Within the call, i'm passing several variables to the component. All of them work fine except for one named totalSpan... which is returning a NaN for some reason. Here's the code I'm working with:
Parent:
<mx:Repeater id="indPositions" dataProvider="{projectPositions}" startingIndex="0" count="{projectPositions.length}">
<components:block height="28"
id="thisBlock" visible="true" horizontalScrollPolicy="off"
width="{projectWidth}"
oneDay="{Number(oneDay)}"
offSet="{indPositions.currentItem[0]}"
numDays="{indPositions.currentItem[1]}"
position="{indPositions.currentItem[2]}"
sName="{indPositions.currentItem[3]}"
projectName="{projectTitle}"
totalSpan="{Number(Math.round(projectWidth.vl / oneDay))}"
/>
</mx:Repeater>
All of the variables in there work fine and will typeof() just fine.
Here's the child code:
[Bindable] public var totalSpan:Number;
and then in the init() function I perform a simple:
Alert.show(String(totalSpan));
The alert returns "NaN".
On a semi-related note, i'm getting warnings on the following lines of the parent:
offSet="{indPositions.currentItem[0]}"
numDays="{indPositions.currentItem[1]}"
position="{indPositions.currentItem[2]}"
sName="{indPositions.currentItem[3]}"
with an message that says "Data binding will not be able to detect chances when using square bracket operator. For Array, please use ArrayCollection.getItemAt() instead.
Can anybody shed some light on these warning errors? an example would be greatly appreciated.
First of all the assignment of
totalSpanis the following:but from
width="{projectWidth}"we can seeprojectWidthis aNumberorint. So it hasn'tvlproperty. And yourNumber(Math.round(projectWidth.vl / oneDay))isNaN. Please rewrite it properly. Maybe it should be the following:About the second part. If you're using {} in MXML it stands for data binding. Data binding provides changes in target attributes with changes of source. And the message says
Arrayis a primitive type andmxmlccompiler can't generate code for it to handle changes in array's values.But it is obvious from code you have some problems with data structures. It is very hard to improve it do not having the whole project's code but you should use custom data types with required
[Bindable]metadata for data binding andArrayCollectioninstead ofArrayfor data used as a source of data binding.Try to create something like:
and put these items to data provider of your repeater. As far as I can understand now your data provider is for repeater length but in real life it should provide repeater elements data. So if you pass into your repeater an
ArrayCollectionof your customMyDataObjectobjects you can use something like the following:And even more. You can pass the whole object of
MyDataObjecttype to yourcomponents:blockcomponent:Hope these thoughts help!