【问题标题】:How to pass a CustomEvent as an argument and dispatch it?如何将 CustomEvent 作为参数传递并调度它?
【发布时间】:2011-06-03 11:29:09
【问题描述】:

如何将 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 事件。

【问题讨论】:

  • 你能澄清一下吗?您是在问如何实现某些目标而发布代码......... 究竟实现了什么?
  • 这似乎是部分代码。你能发布调用 selected() 函数的代码吗,或者甚至有一个?
  • 嘿,Event 如何调度另一个事件?它本身是由某人派遣的吗?我无法弄清楚事件对象将如何引发 ADDED_TO_STAGE 事件
  • 对不起,伙计们需要睡觉。简单的问题 - 在下面回答

标签: actionscript-3 events arguments


【解决方案1】:

刚刚意识到我需要传递的不是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));
}

【讨论】:

    猜你喜欢
    • 2013-12-30
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 2015-09-10
    相关资源
    最近更新 更多