Flex コンポーネントの破棄 注意点
♥2 |
Line 31 |
Modified 2010-05-13 09:53:42 |
MIT License
archived:2017-03-05 06:44:30
ActionScript3 source code
/**
* Copyright matsu ( http://wonderfl.net/user/matsu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qjmQ
*/
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init(event);">
<mx:Script>
<![CDATA[
private function init(evt:Event):void
{
removeButton.addEventListener(MouseEvent.CLICK,removeButtonClick);
bButton.addEventListener(MouseEvent.CLICK,aButtonClick);
cButton.addEventListener(MouseEvent.CLICK,aButtonClick);
}
private function removeButtonClick(evt:Event):void
{
// aButton は、インラインで追加したイベントハンドラなので、removeEventListener() メソッドを呼び出すことはできない
aButton.removeEventListener(MouseEvent.CLICK,aButtonClick);
bButton.removeEventListener(MouseEvent.CLICK,aButtonClick);
cButton.removeEventListener(MouseEvent.CLICK,aButtonClick);
/*
myBox.removeChild(aButton);
myBox.removeChild(bButton);
myBox.removeChild(cButton);
*/
}
private function aButtonClick(evt:Event):void {
logTextArea.text += "click!\n";
}
]]>
</mx:Script>
<mx:Panel>
<mx:Box id="myBox" direction="vertical" height="100" width="125">
<mx:Button id="aButton" label="A" click="aButtonClick(event)"/>
<mx:Button id="bButton" label="B"/>
<mx:Button id="cButton" label="C"/>
</mx:Box>
</mx:Panel>
<mx:Button id="removeButton" label="Remove ButtonEvent"/>
<mx:TextArea id="logTextArea" width="125" height="100"/>
</mx:Application>