Een mooie uitleg over de Document class die we gebruiken in Flash:
ActionScript 3 with Flash 9 lets you specify a "Document Class" (aka Application class) for the main timeline. This represents the class of the root object - the display object in which (essentially) all other display objects are placed.
You can set the Document class in the Document Class option of the Property Inspector for a document with nothing selected. You can also set the Document Class in the ActionScript 3 Settings dialog using File > Publish Settings > Flash [Tab] > Settings... [Button (for ActionScript 3)]. When defining the Document class, you simply provide the name of the class which is to pose as the class for your document. Note: This class should exist within your class path.
The Document Class for Flash needs to extend Sprite or any subclass of Sprite (flash.display.Sprite) to be valid. If you use the main timeline for ActionScript at all in Flash, you would want your document class to extend MovieClip (flash.display.MovieClip) since MovieClips, unlike Sprites, support frames.
A document class should also be public (along with its constructor which is inherently public). A non-public class will result in an error when you publish your movie.
When published from Flash, SWF meta tags within Document Classes are ignored and the settings within Flash are used.
Unlike other display object classes you make, the stage property of a Document class will always be accessible since the document class is inherently a child of the stage. Similarly, if you place any objects on the main timeline in Flash, the will already be children of the Document class when its instantiated.
Example of a Document class:
package {
import flash.events.Event;
import flash.display.MovieClip;
public class CustomDocument extends MovieClip {
public function CustomDocument() {
addEventListener(Event.ADDED, checkChildren);
checkChildren(new Event("initialize"));
}
private function checkChildren(evt:Event):void {
// only allow one child in root
if (numChildren > 1) {
throw (new Error("This movie can have only one child instance"));
}
}
}
}
This class only allows one child. If more are added, an error is thrown. Notice that the checkChildren method is also automatically called in the constructor since its possible that objects could have been added to the timeline within Flash which would have been before the added event listener was created.
Bron: http://www.kirupa.com/forum/showthread.php?p=1950401#post1950401
Joren De Smet
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten