0

我是 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
}

任何人都可以帮忙吗?

4

0 回答 0