As we have already seen, we can create an istance of a class this way:
var nomeIstanza:NomeClasse=new NomeClasse();
But, following the advice of a guru Adobe's Flash Architect ( Colin Moock ), the best solution in AS 3.0 to create an instance of our Main Class ( meaning the Class which will handle the full application and SubClasses ) is the text field that we have in the Properties panel called Document Class. In fact in AS 3.0 the Main Class is being called Document Class.
The Document Class represents the main Timeline of our project ( FLA ) and, usually, is a SubClass of the MovieClip Class.
So the Miles Class that we have seen before will be as follow:
Code:
package
{
import flash.display.MovieClip;
public class Miles extends MovieClip
{
public function Miles()
{
trace('Here i am');
}
}
}
And in the Properties panel (field Document Class) let's write: Miles.
Now we have created an instance of the Miles Class which represents the Timeline of the Fla from which it has been created. So, if from the Class we use a trace command to find out, for example, how many frames there is in total on our Timeline:
Code:
package
{
import flash.display.MovieClip;
public class Miles extends MovieClip
{
public function Miles()
{
trace('la Classe Miles è stata istanziata');
trace(this.totalFrames);
}
}
}
Stay tuned!