USERNAME:
PASSWORD:
Save Info!
Logging in…
This topic is 1 page long.
[ Profile | Posts | Contact ]
Posted at: 6/9/09 05:42 PM
Sign-Up: 03/26/08
Posts: 549
Does anybody know the replacement for the AS2 _root. level method
_root.onLoad = function(){ // Do Stuff // }
In AS3, I tried
function displayOpeningMessage (event:Event):void{ trace(openingMessage) } stage.addEventListener(Event.COMPLETE, displayOpeningMessage);
And "openingMessage" is a String which otherwise appears when running a trace(); This above code does nothing when I test the .swf
AS2 Main | AS3 Main | I came, I listened, I lol'd
Posted at: 6/9/09 05:51 PM
Sign-Up: 08/10/05
Posts: 6,031
As far as I'm aware you don't need it, nor do you need it in AS2, except when loading a MovieClip. If you just put code on the timeline it will execute in the same manor as if it was in an onLoad function. If you want to use it when a MovieClip is loaded on to the stage you can give the class a constructor function.
Portfolio(Under construction): UnknownFury.com | Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com Follow me on twitter!
Posted at: 6/9/09 05:54 PM
Oh, ok... It's just that I wanted to organize it in a function... But I found a work-around, just put it in an ENTER_FRAME, and then within the function, remove the EventListener...
Posted at: 6/9/09 06:02 PM
Sign-Up: 03/02/02
Posts: 13,466
Look into using a document class. The constructor of the document class will fire exactly once, when the .swf is loaded. You can also fill the document class with functions that apply to the scope of the .swf file as a whole (like pausing a game for example)
Posted at: 6/9/09 06:04 PM
At 6/9/09 05:54 PM, Oldsage10 wrote: Oh, ok... It's just that I wanted to organize it in a function... But I found a work-around, just put it in an ENTER_FRAME, and then within the function, remove the EventListener...
you can do that too, no need for an enter_frame. just put this on the first frame.
function init():void { //stuff goes here } init();
if you're worried about the first frame being revisited, you can use a boolean to make sure that init can only get called once ever.
Posted at: 6/9/09 06:55 PM
Thanks Afro, I'm trying to slowly move over to AS3, so I've gotta learn this kind of stuff!
All times are Eastern Standard Time (GMT -5) | Current Time: 07:29 PM
<< Back