为了保障原创作者在本站发表文章的利益, 并维护本站原创的精神, 特声明: RIAShanghai对有以下任何情况之一的文章将不通知作者并直接进行快意删除:
- 非原创, 或者原创但一文多发;
- 各种形式的广告与吹擂;
- 不符合本站文章格式.
欢迎各位读者监督. 谢谢合作. 另: 作为Adobe正式的UG, 我们将把Adobe不定期分发的软件,书籍及各种纪念品赠送给发文活跃的作者, 共同进步.
Events added, addedToStage, removed and removedFromStage offer a great opportunity for performing initialization and cleaning up. Here, I refer the four types of events as display list events. The basic information on display list events can be found in Flex API. However, the API does not have answers for following questions:
We try to find the answers with the following experiment:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="onCreationComplete();">
<mx:Button id="control" label="Remove" toggle="true" selected="false" click="toggleAddRemove();"/>
<mx:Panel width="400" height="120" layout="absolute" id="form">
<mx:HBox width="100%" height="50%" id="box">
<mx:Button label="Button" id="button"/>
</mx:HBox>
</mx:Panel>
</mx:Application>
When the top button is clicked, it toggles to remove/add the form from/to the application.
Register listeners:
private function onCreationComplete():void {
box.addEventListener(Event.ADDED, onEvent);
box.addEventListener(Event.ADDED_TO_STAGE, onEvent);
form.addEventListener(Event.ADDED, onEvent);
form.addEventListener(Event.ADDED_TO_STAGE, onEvent);
button.addEventListener(Event.ADDED, onEvent);
button.addEventListener(Event.ADDED_TO_STAGE, onEvent);
box.addEventListener(Event.REMOVED, onEvent);
box.addEventListener(Event.REMOVED_FROM_STAGE, onEvent);
form.addEventListener(Event.REMOVED, onEvent);
form.addEventListener(Event.REMOVED_FROM_STAGE, onEvent);
button.addEventListener(Event.REMOVED, onEvent);
button.addEventListener(Event.REMOVED_FROM_STAGE, onEvent);
}
private function onEvent(event:Event):void {
trace(event.target + "\t" + event.type);
}
Below is the list of events fired:
// initial
TestRemove0.form addedToStage
TestRemove0.form.box addedToStage
TestRemove0.form.box.button addedToStage
// top button is clicked to remove the form
TestRemove0.form removed
TestRemove0.form removedFromStage
TestRemove0.form.box removedFromStage
TestRemove0.form.box.button removedFromStage
// top button is clicked to add the form back
TestRemove0.form.border removed
TestRemove0.form.border added
TestRemove0.form.UIComponent11.TitleBackground18 removed
TestRemove0.form.UIComponent11.TitleBackground35 added
TestRemove0.form added
TestRemove0.form addedToStage
TestRemove0.form.box addedToStage
TestRemove0.form.box.button addedToStage
TestRemove0.form.box.button.upSkin removed
TestRemove0.form.box.button.upSkin removed
TestRemove0.form.box.button.upSkin removed
TestRemove0.form.box.button.upSkin added
TestRemove0.form.box.button.upSkin added
TestRemove0.form.box.button.upSkin added
// top button is clicked to remove the form again
TestRemove0.form removed
TestRemove0.form removedFromStage
TestRemove0.form.box removedFromStage
TestRemove0.form.box.button removedFromStage
Jack's conclusions