Using ActionScript 3.0 Components |
|
|
|
| Working with Components > Working with the display list > Removing a component from the display list | |||
You can remove a component from a display object container and its display list with the removeChild() and removeChildAt() methods. The following example places three Button components in front of each other on the Stage and adds an event listener for each of them. When you click each Button, the event handler removes it from the display list and the Stage.
To remove a component from the display list:
import fl.controls.Button;
var i:int = 0;
while(i++ < 3) {
makeButton(i);
}
function removeButton(event:MouseEvent):void {
removeChildAt(numChildren -1);
}
function makeButton(num) {
var aButton:Button = new Button();
aButton.name = "Button" + num;
aButton.label = aButton.name;
aButton.move(200, 200);
addChild(aButton);
aButton.addEventListener(MouseEvent.CLICK, removeButton);
}
For a complete explanation of the display list, see Display programming in Programming ActionScript 3.0.
|
|
|
|