If we look to the Actionscript side, we discover that the Timeline of a FLA is nothing else then an instance of the Document Class.
To declare the Document Class to our FLA, we need to write the name of that class (without the .as extension) in the text field ‘Document Class’ in the property panel (at the bottom), as explained in the article on
how to best declare a Document Class .
The Document Class extends the MovieClip Class, except in a few cases? Next, I will list the cases when those classes has to be subclasses of the MovieClip:
- If the timeline contains codes or scripts on frames
- If we want to control the timeline using the method of the MovieClip Class
- If the timeline contains components with personalised parameters or if: o The personalized parameters of the component present on the timeline are different from one frame to another. Example: the label property of a Button is ?OK? in the first frame and ?INVIA? in the second frame.
o The component placed on stage is not present on every frame of the timeline.
- If the timeline?s stage contains any component with personalised properties
If the FLA does not enter in any of the above case, the Document Class can then inherit of the Sprite Class.
Let us say that we decide to assign to the FLA a Document Class named ?Main.as?. We would write the name ?Main? in the property panel. If we would do a typing error and write ?Maina? for example, Flash would automatically create a class named ?Maina? and this ?auto? created class will extends the MovieClip Class.
If the FLA do not specify a Document Class, Flash will automatically create one.
If the following conditions are met in the FLA, the assigned class will be by default the MovieClip (flash.display.MovieClip):
- The timeline?s stage contains instance without name
- The timeline does not contain any codes or scripts on any frame
- The timeline?s stage does not contain components with personalised parameters
- The timeline?s stage does not contain components with personalised properties
If the FLA does not enter in any of the above case and the Document Class has not been assigned, Flash will by default create e Document Class which extends the MovieClip Class.
Every scripts placed on frames of the timeline can be, more or less, seen as methods? instances of the Document Class. The codes found on a frame of the timeline can be executed by Flash, independently of the methods or properties declared in the Document Class (clearly, if they do not have the same names). On the other side, any methods or properties assigned in the Document Class are directly accessible from any script on the timeline.
I will make an example:
I have a FLA named ?filippo.fla? to which I assign a Document Class ?Filippo.as?.
In the Filippo Class, ho un metodo vaiAlSito:
Code:
package
{
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.net.navigateToURL;
public class Filippo extends MovieClip
{
public function Filippo()
{
}
private function vaiAlSito(url:String):void
{
var richiesta:URLRequest=new URLRequest(url);
navigateToURL(richiesta,'_blank');
}
}
}
The best part is now coming?
In my FLA, I create a keyframe at frame 9.
As we can see in the Filippo Class, the method vaiAlSito redirect the user?s browser to a chosen URL.
If now, we would like to execute the same action from frame 9 in our FLA, we could do it 2 different ways:
Code:
var richiesta:URLRequest=new URLRequest('http://www.flepstudio.org');
navigateToURL(richiesta,'_blank');
stop();
Code:
vaiAlSito('http://www.flepstudio.org');
stop();
This elasticity of communication in between the Document Class and the timeline, allows even to apprentice ?actionscripters? to use a Document Class into which the functions (methods) can be written and easily recalled from the timeline.
See you soon!