flash native_classes_real_constructor
A real constructor
In ActionScript 1 and 2, it was possible to extend a MovieClip class. The principle was virtually the same, a symbol was defined in the library, then a class was linked to the symbol.
Note, it is important to note that in ActionScript 2 the graphic sub-class that we could define was linked to the symbol. This meant that calling the attachMovie method instantiates the class.
In ActionScript 3, thanks to the new instantiation model for graphic objects, it is now the symbol that is linked to the class. This means that the instantiation of the sub-class leads to the display of the symbol and not the other way around.
The only way to instantiate our graphic sub-class in ActionScript 2 was to call the attachMovie method.
ActionScript 2 in contrast to ActionScript 3 suffered from cumbersome inheritance, the instantiation process of graphic objects was outdated and didn’t sit comfortably with the object model. The player triggered the constructor of the graphic class. It was impossible to pass the initialisation parameters, only the initialisation object (initObject) allowed you to pass the properties before the constructor was even triggered.
By instantiating the sub-class, the symbol was not displayed, the following code does not work as the only way to display the clip for the player was the attachMovie method:
// the sub-class was instanced but the symbol wasn’t displayed var mySymbol:SubClassMC = new SubClassMC();
The link between the symbol and the class happened only by using the Linking properties panel, it was therefore impossible to link a class to a graphic object created programmatically.
ActionScript 3 corrects this. In the following example we will create a sub-class of flash.display.Sprite, without creating a symbol in the library everything will be made dynamically.
Worth remembering
- In ActionScript 2 it was impossible to pass parameters to the constructor of a graphic sub-class.
- In order to solve this problem, we use the initialization object available in the attachMovie method.
- ActionScript 3 sorts all this out, thanks to the new instantiation model of graphic objects.
- In ActionScript 2 the class was linked to the symbol. Only the attachMovie method allowed for the instantiation of the graphic sub-class.
- In ActionScript 3 the symbol is linked to the class. The instantiation of the sub-class, by the keyword new, leads to the creation of the symbol.
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


