Articles Tagged 'constructor'

Flash: how to initialize the components in the constructor of a class

When estente a class from other objects that it contains a MovieClip (MovieClip, TextField, etc ...) they may not be "ready" within the constructor. This happens especially when using more extended MovieClip or components (controls) of Flash. To solve the problem just use the onLoad event inherited from the class itself. For example imagine you have a MovieClip that contains a TextField object (static visual object inside flash) and a TextInput object (inserted control panel components) and want to set some property in the constructor of our class MyClass.

Example We create a symbol and insert inside either object TextField (let's call text_txt) is the TextInput object (textinput_txt). We associate this symbol to a class that extends MovieClip, call our class MyClass. What we get is that during the constructor of our class MyClass these two controls are initialized. If we try to use a code like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/ /
controls . TextInput ; import mx. controls. TextInput;
/ /
MovieClip { class MyClass extends MovieClip {
/ /
text_txt : TextField ; private var text_txt: TextField ;
textinput_txt : TextInput ; private var textinput_txt: TextInput;
/ /
function MyClass () {
"MiaClasse::costruttore" ) ; trace ("MyClass :: constructor");
/ /
= "Ciao" ; text_txt. text = "Hello";
= "Ciao" ; textinput_txt. text = "Hello";
/ /
}

}

More ...


Stop SOPA