我构建了一个传递变量的自定义事件调度程序。我派遣活动,然后尝试在文档根目录中听取活动,但我从未收到活动。我如何将活动冒泡到我的文档类?如何从ActionScript 3派发自定义事件并在文档根目录中侦听它?
addEventListener(CustomVarEvent.pinClicked, pinClickedHandler);
function pinClickedHandler(e:CustomVarEvent) {
trace("main says " + e.arg[0] + " clicked");//access arguments array
}
package zoomify.viewer
{
import com.maps.CustomVarEvent;
protected function hotspotClickHandler(event:MouseEvent):void {
var hotspotData:Hotspot = hotspotsMap[event.currentTarget] as Hotspot;
trace(hotspotData._name + " was clicked");
/*if(hotspotData) {
navigateToURL(new URLRequest(hotspotData.url), hotspotData.urlTarget);
}*/
dispatchEvent(new CustomVarEvent("pinClicked",true,false,hotspotData._name));
}
}
package com.maps
{
// Import class
import flash.events.Event;
// CustomVarEvent
public class CustomVarEvent extends Event {
public static const pinClicked:String = "pinClicked";
// Properties
public var arg:*;
// Constructor
public function CustomVarEvent(type:String, ... a:*) {
var bubbles:Boolean = true;
var cancelable:Boolean = false;
super(type, bubbles, cancelable);
arg = a;
}
// Override clone
override public function clone():Event{
return new CustomVarEvent(type, arg);
};
}
}
是被分派在类深嵌套两个层次的pinClicked事件。我将一个类ZoomifyViewer的实例添加到舞台上。 ZoomifyViewer将ZoomGrid的实例添加到舞台上,ZoomGrid将调度该事件。
当我将相同的事件侦听器和处理函数直接添加到我的ZoomGrid类(与事件派发的类相同)中时,侦听器和处理程序正常工作。但是,当监听者和处理程序在父类或舞台上时,我没有得到任何回应。
调度员是否需要冒泡泡?
此外,这两行功能相同基于在我的CustomVarEvent定义的常数pinClicked?
dispatchEvent(new CustomVarEvent(CustomVarEvent.pinClicked, hotspotData._name));
dispatchEvent(new CustomVarEvent("pinClicked", hotspotData._name));
对不起,但是这个答案除了我提供的那个副本外什么都没有? – Stiggler 2009-04-15 18:25:08