我在flex编程方面是全新的,在我的代码中,我觉得听众没有被正确删除。下面是代码作为我所做的一个例子。这个代码第一次被执行,一切都很好,我看到了各种警报,我已经添加了跟踪路径。但是从第二次开始只看到警报信息:
Alert.show('saveMapImageAndForward:before 2');
没有其他消息。我究竟做错了什么?我是否正确地正确移除了听众?代码路径应该是: saveMapImageAndForward-> processMapImage-> addMapImage - > saveMapImage
我创建了一个全局计时器: private var timer:Timer = new Timer(1000);
这是我的代码:
public function saveMapImageAndForward(projectLocationWKT:String, projectMapType:String, hasMapImageFromIPaCMap:String, projectName:String):void {
this.projectLocationWKT = projectLocationWKT;
this.projectMapType = projectMapType;
this.hasMapImageFromIPaCMap = hasMapImageFromIPaCMap;
this.projectName = projectName;
Alert.show('saveMapImageAndForward:before 2');
_map.addEventListener(ZoomEvent.ZOOM_END, processMapImage);
GlobalDispatcher.dispatchEvent(new AppEvent(DrawManager.ZOOM_TO_SELECTION));
}
//On zoom_end this function will be called
private function processMapImage(pEvent:ZoomEvent):void {
Alert.show('inside processMapImage');
_map.removeEventListener(ZoomEvent.ZOOM_END, processMapImage);
Alert.show('after ZoomEvent removed');
timer.addEventListener(TimerEvent.TIMER,addMapImage);
timer.start();
}
//I need a delay of 1 sec so starting a timer
private function addMapImage(pEvent:TimerEvent):void {
Alert.show('inside addMapImage');
timer.stop();
timer.removeEventListener(TimerEvent.TIMER,addMapImage);
Alert.show('after timer removed');
saveMapImage();
}
//after 1 sec this method will be called
public function saveMapImage():void {
//do something
}
有人可以帮忙吗?