Well, it appears that in my previous posts about ActionScript 3.0, I am a bit old school. I have been instantiating my code from the first frame of the timeline using the import statement. After opening up a few of the as3_labs_samples_062706 and realizing that there is no code on the timeline, just a disclaimer, I started to scratch my head. I checked the library of the .fla to see if I could see any linkages. Still, I could not find any reference to the external code. The next place I checked was the Publish Settings (Ctrl-Shift+F12) and lo and behold, I found my answer. If you click on the Flash tab, then on the settings… button you will see the new Document class: field. Using this field you can instantiate your code. This is a much cleaner way of doing things. Finally a Flash Developer’s dream come true, no more code on the timeline.
Haha
yeah Fraser it was weird at first, but I’m pretty sure most of us will be in your situation. ActionScript is trully an OOP language now and having to use class linkage to our symbols will make everyone’s lives easier.
good job on the tutorials. it helped me get use to the new features ActionScript 3.0 has to offer.
cschua
Thanks Fraser, great stuff. Searching livedocs for “Document class” brings up nothing, thank goodness for googledocs
that brings up your post at the top of the list.
And no more code on the timeline means *no* more code, not even comments!
The Document Class seems like a great addition to the environment. One problem I’m having is placing something on the stage and having a Document Class. Doing so results in all kinds of errors…
I looked inside each of the as3_labs_samples and it seems like its either one way or the other. Either there is a document class with no objects on stage, or there are objects/ui/artwork on stage and there is no document class.
Anyone know the correct way to merge the two?
It’s actually very simple once you see it
If I define a class in Main.as in the same directory as my .fla file containing the code:
package{
import flash.display.MovieClip;
import flash.events.*;
// Class definition
public class Main extends MovieClip{
public var myMc:myClip;
// Class Constructor
function Main(){
myMc.stop();
myMc.addEventListener(MouseEvent.MOUSE_DOWN,
PressListener);
}
// Handle mouse press over myMc
private function PressListener(evt:Event):void{
if(myMc.currentFrame == 1){
myMc.gotoAndStop(2);
}else myMc.gotoAndStop(1);
}
}
}
Then I can drag a MovieClip having the linkage name myClip onto the stage, it’s instance name will be myMc (I have to define this in my Main class as public var myMc:myClip;) and acces it from inside my Main class.
If I don’t define it or define it as a private member flash will throw an error.
Hope this helps
it works for me only without
“public var myMc:myClip;”
but thanks
That’s because Orsike has opted to disable the automatic declaration of stage instances (enabled by default under publish settings -> ActionScript 3.0 Settings).