Hi all,
It's me again I've changed my strategy for this problem: http://board.flashkit.com/board/show...09#post4305709
I now want to try to update my component using a custom event. So the main problem still is: in my application I load 1 data file in the main mxml. After it loads some processing is done on it and the data is stored in an ArrayCollection. This collection holds data for three years. I want to visualise this year data by letting users click on a button labelled with that year. I call an eventhandler in the main mxml file that updates a variable named currentYear and passes this value on to a variable called year (in my new approach using a custom event, view code below) in an ItemRenderer which should then display the data from this specific year.
Now I dispatch a custom event in the main mxml like this when a button of a certain year is clicked:
PHP Code:
protected function btn01ClickHandler(event:MouseEvent):void{
currentYear = "2001";
var myEvent:ChangeYearEvent = new ChangeYearEvent(currentYear);
this.dispatchEvent(myEvent);
}
The custom event that passes on the selected year value is called ChangeYearEvent looks like this (pretty basic):
PHP Code:
package events
{
import flash.events.Event;
public class ChangeYearEvent extends Event
{
public var year:String;
public static const CHANGE_YEAR:String = "change_year";
public function ChangeYearEvent(year:String)
{
super(type);
this.year = year;
}
override public function clone():Event {
return new ChangeYearEvent(year);
}
}
}
In my ItemRenderer which has to work with the data from a specific year I try to access the data like 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" creationComplete="init()">
import mx.collections.ArrayCollection;
private function init():void{
systemManager.addEventListener(ChangeYearEvent.CHANGE_YEAR, setYear, true);
}
private function setYear(evt:Event){
trace("year:"+evt.year);
// and some other stuff, this is just to show the approach
}
</s:ItemRenderer>
The problem is that evt.year isn't found: access to an undefined property... Why? What am I missing here? The event is coming in but I can't access the property of the event. Any help is greatly appreciated. TIA.