flash display_list_instancing
Instancing of graphic classes
One of the latest advances in ActionScript 3 involves the instantiation procedure of graphic classes. Before ActionScript 3 we had to use different methods such as createEmptyMovieClip to create flash.display.MovieClips or even createTextField for the flash.text.TextField class. We had to memorise numerous methods that weren’t necessarily easy for somebody new to ActionScript. From now on we will use the keyword new to instantiate all graphic objects.
The following code creates a new instance of MovieClip.
var myClip:MovieClip = new MovieClip();
If we want to create a dynamic textfield we write:
var myTextField:TextField = new TextField();
To add text to our textfield we use the text property of the TextField class:
var myTextField:TextField = new TextField(); myTextField.text = "Hello World";
Using createTextField or createEmptyMovieClip methods obliges us to keep a reference to a MovieClip in order to be able to instance our graphic objects. With the use of the keyword new all of that is just a bad memory.
We no longer need to specify the occurrence name or the depth during the instantiation phase. Even if our graphic object has been created and is in the memory, it will not have been added to the display list yet. If we test the previous code we will see that the text is not displayed.
One of the more troubling behaviors upon discovering ActionScript 3 is the off list display objects.
Worth remembering
- For a graphic object to be visible it has to be added to the display list
- All the graphic objects are instantiated with the keyword new.
Mediabox Training Centre © 2000 - 2008 All rights reserved.
Adobe Authorized Training Centre. State convention under number 25 14 02167 14.
Mediabox : SARL au capital de 62.000€ - Activity number: 25 14 02167 14 - SIRET : 493 716 468 00027
MEDIABOX, 102 Avenue des Champs Elysées, 75008 PARIS - Tel. +33(0)2.31.91.96.89 - Fax. +33(0)2.72.68.56.42


