I'm having trouble getting an event listener to work in a mobile app (Built in Flash Builder 4.5, Flex SDK 4.5.1)
I have an event class called BMS_Event.as which looks like this:
package model
{
import flash.events.Event;
public class BMS_Event extends Event
{
public static var COMPLETE_EVENT:String = "BMSData_Complete";
public static var FAULT:String = "BMSDatafault";
public var data:*;
public function BMS_Event(type:String, data:*=null, bubbles:Boolean=false, cancelable:Boolean=false)
{
this.data = data;
super(type, bubbles, cancelable);
}
}
}
A class to dispatch the event:
package model
{
import flash.events.Event;
import flash.events.EventDispatcher;
import model.BMS_Event;
public class BMSDataParser extends EventDispatcher
{
public function BMSDataParser()
{
trace("BMSDataParser function");
var BMSDataCompleteEvent:BMS_Event开发者_如何学编程 = new BMS_Event(BMS_Event.COMPLETE_EVENT);
dispatchEvent(BMSDataCompleteEvent);
}
}
}
And in my Mobile App view, two functions to call the eventparser, and then an eventlistener which listens for the complete event:
import model.BMSDataParser;
import model.BMS_Event;
protected function getData():void
{
var parser:BMSDataParser = new BMSDataParser();
parser.addEventListener(BMS_Event.COMPLETE_EVENT, bmstest);
}
private function bmstest(e:BMS_Event):void
{
trace("bmstest function");
}
The problem I'm having is that the event listener isn't firing, everything works fine up until that point. It does work in a web application, but for whatever reason not a mobile app. I'm new to mobile app development - is this a limitation of AIR mobile Apps?
Any help/suggestions greatly appreciated. Thanks
Maybe make var parser:BMSDataParser
a private class variable, and in the creationComplete
or initialized
events of the class add parser.addEventListener(BMS_Event.COMPLETE_EVENT, bmstest);
One more thing: if your using ViewNavigatorApplication with Views, the views are not created until they are pushed onto the view stack e.g. navigator.pushView(PayNowView);
, so any listeners will not be activated unless they are displayed first
精彩评论