Add movie object dynamically with actionscript (flash)

QuintusSmit
QuintusSmit used Ask the Experts™
on
Hi

I am playing around with actionscript 3 in flash and would like to know if it is possible to add objects(movie or button) or new instances of objects using actionscript as needed for example by clicking a button.

thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009
Commented:
in order to add things at runtime you use the addChild() or addChildAt(name, index);

so for example if you have a Ball in your library with properties

var ball:Ball = new Ball();
addChild(ball);
then you can specify x and y location etc.

so for a button you use an event listener


var myButton:Button = new Button();
myButton.addEventListener(MouseEvent.CLICK, doAddChild);


function doAddChild(e:MouseEvent):void
{
var ball:Ball = new Ball();
addChild(ball);
}

that's the basics. how you set it up depends on your class structures.

Author

Commented:
Thank you

This is what I was looking for

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial