Hi all,
So far I've had no replies so I would like to explain a little more and add some code. I've been doing some more searching and I think I just need an eventlistener in my ItemRenderer but I don't know how to go about it.
In main.mxml I've got a variable that hold the current year, a button and a handler for the click event like this:
As you can see the value for the current year is passed to the ItemRenderen "MenRowRenderer" which has a variable called year and a function setYear() to set that year. In the function override public function set data(value:Object) I use the setYear() function to populate the ArrayCollection "men" with the data from the current year. This array is then passed on to a child ItemRenderer "MenIconRenderer". MenRowRenderer.mxml:PHP Code:<s:FormItem label="">
[Bindable] private var currentYear:String = "";
<s:Button id="btn_1996"
label="1996"
click="btn96ClickHandler(event)"/>
</s:FormItem>
protected function btn96ClickHandler(event:MouseEvent):void{
currentYear = "1996";
components.MenRowRenderer.year = currentYear;
}
So what I want is for the MenRowRenderer to refresh the data in the "men" ArrayCollection every time a year button is clicked in the main.mxml and pass that data on to the child ItemRenderer "MenIconRenderer" and update that visualisation. So far I've only been able to render one year and not change between years. How can I achieve this?PHP Code:<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import valueObjects.YearPopulationSlice;
[Bindable] private var men:ArrayCollection = new ArrayCollection();
[Bindable] public static var year:String;
private static const GRAIN:int = 10000;
override public function set data(value:Object):void{
super.data = value;
if(value){
var people:YearPopulationSlice = new YearPopulationSlice();
people.pop = value["pop"+setYear()]/GRAIN;
people.immi = value["immi"+setYear()]/GRAIN;
people.emi = value["emi"+setYear()]/GRAIN;
people.death = value["death"+setYear()]/GRAIN;
men.addItem(people);
}
}
private function setYear():String{
if(year == "1996"){
yearSet = "96";
}
if(year == "2001"){
yearSet = "01";
}
if(year == "2006"){
yearSet = "06";
}
trace("year:"+yearSet);
return yearSet;
}
]]>
</fx:Script>
<s:DataGroup id="rowMenRenderer"
dataProvider="{men}"
itemRenderer="components.MenIconRenderer">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
</s:DataGroup>
</s:ItemRenderer>
I hope I've explained my problem a little better this way and really hope someone can help as I've been struggling with it for days. Thanks very much in advance.




Reply With Quote