简体   繁体   English

创建自己的ADDED_TO_STAGE事件

[英]Creating your own ADDED_TO_STAGE event

Is it possible to create your own ADDED_TO_STAGE event? 是否可以创建自己的ADDED_TO_STAGE事件?

I´m trying to pass some arguments to its handler... 我正在尝试将一些参数传递给它的处理程序...

It would be like this: 就像这样:

addEventListener(Event.ADDED_TO_STAGE, arg1, arg2, init) addEventListener(Event.ADDED_TO_STAGE,arg1,arg2,init)

There´s any workaround for this? 有什么解决方法吗?

Thanks. 谢谢。

Visiting this link will provide an in-depth answer on this, however here's a quick and dirty snapshot: 访问此链接将提供对此的深入解答,但是,这里有一个快速而肮脏的快照:

A function called by a listener can only have one argument, which is the event triggering it. 侦听器调用的函数只能有一个参数,即触发它的事件。

You will need to either call another function from your listener function, or create a custom event to hold the properties you want to parse. 您将需要从侦听器函数调用另一个函数,或者创建一个自定义事件来保存要解析的属性。 The latter is recommended, but here's how you could implement the former: 建议使用后者,但是这里是实现前者的方法:

function init(e:Event):void
{
    removeEventListener(Event.ADDED_TO_STAGE, init);

    finalize(arg1, arg2);
}


function finalize(a:*, b:*):void
{
    trace(a, b);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM