dispatchevent isn't working
I have a strange problem:
I assigned the following variable:
public static const SERIES:String = "series";
Then in the same class I have the following function:
public function imgCompleteHandler(e:Event):void {
var slidesXML:XML = new XML(e.target.data);
for each (var serie:XML in slidesXML.slide){
this.thumbs = serie.image;
series.push(serie);
}
trace("before");
dispatchEvent(new Event(SERIES));
trace("after");
}
This is the class where the event is called:
package be.devine3.groep6.view.components.overview
{
import be.devine3.groep6.model.AppModel;
import be.devine3.groep6.view.components.series.Series;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
public class SerieOverview extends Sprite
{
private var loader:Loader;
private var appModel:AppModel;
public function SerieOverview()
{
this.appModel = AppModel.getInstance();
appModel.addEventListener(AppModel.SERIES, seriesLoadedHandler);
}
public function seriesLoadedHandler(e:Event):void{
for each (var slideModel:XML in appModel.series) {
var serie:Series = new Series(slideModel);
addChild(serie);
}
}
}
}
Now for some reason the 开发者_StackOverflowevent does not get dispatched, the traces I placed before and after the dispatch event both get triggered. Anyone know why the dispatch event doesn't work?
Its kind of hard finding the problem by tje code you posted. Easy check: make sure that you are adding the eventlistener BEFORE the event is dispatched. Add a trace in the method where you add the listener to be sure it is set before the dispatch.
Is your AppModel getInstance() method also initializing the AppModel class? If so the event is likely being dispatched before you add the event listener.
I always use this flow:
1) Create Instance of class
2) Attach initialization event listeners
3) Call a public init() method ( i.e. AppModel.instance().init(); )
精彩评论