如何将CustomEvent作为参数传递并分派它?

时间:2011-06-03 11:29:09

标签: actionscript-3 events arguments

如何将CustomEvent作为参数传递给类,然后再调度它?我想要实现的一个例子是 - 不工作

var container:Container = new Container(array, new ViewEvent(ViewEvent.PHOTO_SELECTED));
addChild(container);

并在容器中:

public class Container extends Sprite

public function Container(array:Array, e:ViewEvent):void
{
     _objectsArray = array;
     _event = e;
     addEventListener(Event.ADDED_TO_STAGE, init);
}

private function selected():void
{
    dispatchEvent(new ViewEvent(_event, true, false, _selectedID));
}

因此,当调用selected()时,将触发传递给构造函数的View事件。

1 个答案:

答案 0 :(得分:0)

刚才意识到我不需要传递Event,而是字符串值。

var container:Container = new Container(array, ViewEvent.PHOTO_SELECTED);

-

public function Container(array:Array, e:String):void
{
 _objectsArray = array;
 _event = e;
 addEventListener(Event.ADDED_TO_STAGE, init);
}

private function selected():void
{
dispatchEvent(new ViewEvent(_event, true, false, _selectedID));
}