Hi!
Just to share my important milestones to understand how to write and use classes combined with timeline code. It might help you! I'm still a beginner!
1. It is not easy to understand it all starting from zero flash experience. You find much good help on the net, but starting from zero and get the full picture takes some time.
2. If you don't create a class file flash does this for you in the background. So to get full control you can always create a classfile with the same name as your movieclip (with the suffix .as). Put it in the same folder as your .fla project file. Then rightclick on the moveclip and select linkage and type your classfile name there.
In the constructor you can do things once at startup! I also have a _doOnce variable that I can use in my movieclip frames (if needed). You reach methods in other movieclip (classes) just by giving each movieclip an instance name (using the property tab). Here is a simple example. Here you have a movieclip called MyMovieclip and a classfile called MyMovieclip.as.
3. You also need to have the main class of your flash application. That is the class that defines the overall behaviour. It might call methods in your moveieclips that your application consists of. This is a good place to have all your events for the user. Create a class file with the same name as your .fla file (in the same folder). Then type in the classname in the properties tab of your scene (Document class property). See this small example...Code:package { import flash.display.MovieClip; public class MyMovieclip extends MovieClip { // State variables private var _doOnce:Boolean; // Constructor public function MyMovieclip () { _doOnce = true; ... } ... } }
4. The build in help is not very helpful. You don't get any help when writing the code (like get a list of all avalibe methods when typing a . after the instance variable). So to have a book in ActionScript 3 is very useful. Like "ActionScript Cookbook O´REILLY". The net also gives some help...Code:package { import flash.display.MovieClip; import flash.events.MouseEvent; import flash.events.KeyboardEvent; import flash.ui.Keyboard; public class MySuperGame extends MovieClip { // State variables private var _doOnce:Boolean; // Constructor public function MySuperGame() { _doOnce = true; // Add event listners stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown); } // On any key down private function reportKeyDown(event:KeyboardEvent) { ... myMovieclip.MyMethod(...); } } ... }
5. The code that you place in the movieclip frames is somehow included in your class. I see the timeline frame code as a method in the class. How this is done is still a bit magic for me. A good rule is to keep the timeline code to a minimum.




Reply With Quote