Event.ADD_TO_STAGE事件
来源:互联网 发布:七喜cms 编辑:程序博客网 时间:2024/04/28 21:36
Display objects often need to perform set-up tasks which depend on the stage. They might wish to access stage.stageWidth
or stage.stageHeight
, for example. The trouble is, the stage
property will return null
until that object is on the Display List.
The standard way around this is to put such set-up tasks in an init
method, which you then trigger separately:
So the init
method is triggered once the object is added to the Display List. This works fine. The only downside is that the object cannot initialise itself. This solution seems slightly clumsy from an OOP point of view also a little verbose. Could the object not auto-trigger its own init
method once it is on the Display List?
Not until Flash Player 9.0.28.0, which added support for the ADDED_TO_STAGE
event, used as follows:
The trouble is, however, this event erroneously fires not only for the given item, but also when its parents are added to the Display List. This runs your init
method multiple times, possibly causing problems.
This issue is Flash Player bug known to Adobe. Read more about the ADDED_TO_STAGE event firing twice issue in the official bug report entry. A workaround with a sample class may be found there. We use that workaround inherited from a superclass for all our display objects, and until the issue is solved we suggest you either use it too, or use the init
method solution when set-up code depends upon the stage.
若干评论:
An other workaround could be, to remove the listener in the handler.
Workaround:
1. Remove the ADDED_TO_STAGE event listener in the ADDED_TO_STAGE event handler.
2. Add a REMOVED_FROM_STAGE event listener on the object.
3. In the REMOVED_FROM_STAGE event handler, add the ADDED_TO_STAGE event again.
- Event.ADD_TO_STAGE事件
- 事件Event
- event事件
- event事件
- 事件(event)
- 事件(event)
- Event事件
- event 事件
- 事件event
- Event 事件
- 事件(Event)
- 事件Event
- 事件Event
- 事件(event)
- Event事件
- event事件
- 事件EVENT
- event 事件
- ARM Linux Kernel Boot Requirements
- 设计模式 之 单例模式
- Dictionary对象的使用
- CSS border-collapse用途
- 【转】淘宝性能测试要点
- Event.ADD_TO_STAGE事件
- ListCtrl 详细用法
- phyeas Seam新手实战(2):自动生成的代码
- CSS 鼠标(cursor)一览表
- C语言宏定义中#用法
- Java获得系统环境变量
- 用C++Builder开发自己的RDP客户端
- Spyder jacket for both men and women
- Automation 服务器不能创建对象