Forum Topic: "_root.onLoad" replacement in AS3?

(111 views • 5 replies)

This topic is 1 page long.

<< < > >>
Questioning

Oldsage10

Reply To Post Reply & Quote

Posted at: 6/9/09 05:42 PM

Oldsage10 DARK LEVEL 13

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


None

UnknownFury

Reply To Post Reply & Quote

Posted at: 6/9/09 05:51 PM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,027

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!


None

Oldsage10

Reply To Post Reply & Quote

Posted at: 6/9/09 05:54 PM

Oldsage10 DARK LEVEL 13

Sign-Up: 03/26/08

Posts: 549

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...


None

Afro-Ninja

Reply To Post Reply & Quote

Posted at: 6/9/09 06:02 PM

Afro-Ninja EVIL LEVEL 38

Sign-Up: 03/02/02

Posts: 13,463

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)

BBS Signature

None

Afro-Ninja

Reply To Post Reply & Quote

Posted at: 6/9/09 06:04 PM

Afro-Ninja EVIL LEVEL 38

Sign-Up: 03/02/02

Posts: 13,463

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.

BBS Signature

None

Oldsage10

Reply To Post Reply & Quote

Posted at: 6/9/09 06:55 PM

Oldsage10 DARK LEVEL 13

Sign-Up: 03/26/08

Posts: 549

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: 04:49 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!