Forum Topic: [as3.0] Document Class / Preloaders

(101 views • 6 replies)

This topic is 1 page long.

<< < > >>
None

Johnny

Reply To Post Reply & Quote

Posted at: 11/5/09 11:39 PM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,445

Well, it's always a learning experience transitioning to a new language. With AS2.0, it was the onLoad function for me.

With AS3.0, it's the document class.

I used it as my main actionscript file, controlling initialization, the main game loop and controller class for all of the other classes.

Now, after trying in vain to get a preloader to work properly, I see the problem in that the Document class is loading before my preloader.

My simple fix was to remove the document class entirely, and on the first frame of my game to just create an instance of my main class on that frame, and then run the init function.

At that point, none of my references to any stage objects would work properly even after attempting adding stage or parent before the clips in question.

Are there any simple ways to repair this situation that you guys have run across?

All sites currently down. Deal with it. <3

BBS Signature

None

henke37

Reply To Post Reply & Quote

Posted at: 11/6/09 01:53 AM

henke37 NEUTRAL LEVEL 23

Sign-Up: 09/10/04

Posts: 3,604

Framescripts are a part of the class for the timeline they are placed on.

Your issue is due to not being on the stage when you need to use it. The solution is to wait for the ADDED_TO_STAGE event.

Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.


None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 11/6/09 03:50 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,383

You don't really need to refer to the stage. Stop doing things stupidly and you won't have problems.
The document class status doesn't mean it should be the main class. In fact it's normally tiny.

In a finished (properly built) app, it'd just add the preloader, then switch to intro animations, then switch to the menu class. The menu class has some buttons, sets some settings (in another class), then triggers the initialization of a game which takes the settings and builds the game facilities, then triggers a class that handles the game loop.
The point is, don't do everything in the main facade singleton document class of doom.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Johnny

Reply To Post Reply & Quote

Posted at: 11/6/09 07:22 AM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,445

At 11/6/09 03:50 AM, GustTheASGuy wrote: Stop doing things stupidly and you won't have problems.

Unfortunately, when transitioning into AS3.0, 2 of the books I used for reference used the shit out of the Document Class, so I was under the assumption that was where the main game loop should reside.

All sites currently down. Deal with it. <3

BBS Signature

None

Johnny

Reply To Post Reply & Quote

Posted at: 11/6/09 05:12 PM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,445

Alright, I hope I've found a workaround...

I was able to get my main initialization/game loop class to work correctly on the 2nd frame and completely removed the document class.

I have my preloader in the first frame.

Should everything work now? I've tried simulating download, but it's always 100% instantly, so I'm cautious.

Should I put the preloader in the Document Class, or leave that blank?
Will there be any problems with things set to "Export to first frame" in their linkage settings?

All sites currently down. Deal with it. <3

BBS Signature

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 11/7/09 07:17 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,383

You don't need an explicit class if you're good with code on the frame. It's the same thing anyway.

Of course there will be problems with that setting. You might even think they'd be exactly the same as in previous version of Flash.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Johnny

Reply To Post Reply & Quote

Posted at: 11/7/09 09:26 AM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,445

At 11/7/09 07:17 AM, GustTheASGuy wrote: You don't need an explicit class if you're good with code on the frame. It's the same thing anyway.

I ended up just leaving the doc class blank and coding the preloader on the first frame, and then calling my class a few frames later.

Of course there will be problems with that setting. You might even think they'd be exactly the same as in previous version of Flash.

Blarg...

All sites currently down. Deal with it. <3

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 07:30 PM

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