Be a Supporter!
Jynxxx
Jynxxx
  • Member since: May. 5, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Preloader in AS3 May. 14th, 2010 @ 02:33 PM Reply

Hey guys.

I've been trying to get my AS3 preloader working correctly and I can't seem to get it right. I'm making this preloader according to the 8bitrocket tutorial - Link

A quick summary of what it is:
1) You first make sure all of your "Linkage" movieclips are set to NOT "Export on Frame 1". (Except for your preloader MC)
2) Add preloader MC to the stage in frame 1, let it load, then once it's done, it'll play() to frame 2 of the timeline.
3) On frame 2 there is a movieclip (typically named "Assets") placed on the stage that contains ALL of your "Linkage" movieclips. This is how to give Flash the ability to reference them later in the game since they weren't "Exported on Frame 1" like usual.
4) The timeline continues to play to frame 3 and stops there. The stage is completely cleared and the game begins like normal.

My problem is this. Since I'm just placing all of my "Linkage" movieclips onto the stage (in step 3 above) I get loads of compiler errors like so:

ArgumentError: Error #1063: Argument count mismatch on com.wow.hud::LevelTransition(). Expected 3, got 0.

ArgumentError: Error #1063: Argument count mismatch on com.wow.misc::Mine(). Expected 4, got 0.

ArgumentError: Error #1063: Argument count mismatch on com.wow.misc::Skidmark(). Expected 2, got 0.

Since this method of getting a preloader on AS3 games is so popular, I'd imagine there is a workaround to this issue that I'm just not seeing. Google isn't helping either.

Any help appreciated!


BBS Signature
meneldil
meneldil
  • Member since: May. 27, 2004
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Preloader in AS3 May. 14th, 2010 @ 03:00 PM Reply

By placing MCs "by hand", your calling their constructors without passing any arguments. But some of them expect arguments.

One quick fix would be giving all of them default values.


Indescriptive topic names have left me in despair!

Jynxxx
Jynxxx
  • Member since: May. 5, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to Preloader in AS3 May. 14th, 2010 @ 05:28 PM Reply

Dude, you're a genius.

I swear sometimes I think I shouldn't be touching Flash.


BBS Signature
Jynxxx
Jynxxx
  • Member since: May. 5, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to Preloader in AS3 May. 14th, 2010 @ 05:46 PM Reply

Meh, I should really learn to expect bad things to happen.

Anyway, your solution did solve my original problem, but now what happens is that even though the MC's are only on the stage for 1 frame, for some reason they now play in the background.

(For example, one of the MC's has an ENTER_FRAME listener that checks what the current frame of the MC is and if it's a certain number it plays a "beep" sound. Now when I start my game I hear the "beep...beep...beep..." in the background even through the MC is removed and its listener has been removed.)

Anyway, is there another way of solving this issue?


BBS Signature
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Preloader in AS3 May. 14th, 2010 @ 06:05 PM Reply

Keep movieclips and game classes separate next time.

I've heard there is a setting to change which frame things are exported on by default. This would be in publish settings I suppose.
You can also package SWFs after they have been exported, as in combining game and preloader SWF files into one, with external tools.


BBS Signature
SantoNinoDeCebu
SantoNinoDeCebu
  • Member since: Jul. 20, 2002
  • Offline.
Forum Stats
Supporter
Level 32
Programmer
Response to Preloader in AS3 May. 14th, 2010 @ 06:17 PM Reply

Instead of playing through frame 2. When the loader finishes playing try gotoAndStop(3); so you jump over frame 2.
This should still load them during the preloader, but not place them on the stage unintendedly.
I *think* that's how the preloader I found works anyway!
I can send it over you can have a look if it doesn't work.

Jynxxx
Jynxxx
  • Member since: May. 5, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to Preloader in AS3 May. 14th, 2010 @ 07:56 PM Reply

At 5/14/10 06:17 PM, SantoNinoDeCebu wrote: Instead of playing through frame 2. When the loader finishes playing try gotoAndStop(3); so you jump over frame 2.
This should still load them during the preloader, but not place them on the stage unintendedly.
I *think* that's how the preloader I found works anyway!
I can send it over you can have a look if it doesn't work.

I'm honestly in disbelief right now that that worked. It seems so simple but I've never seen skipping over frame 2 in all the tutorials I've looked at. But, I think it actually worked... Thanks alot!


BBS Signature
SantoNinoDeCebu
SantoNinoDeCebu
  • Member since: Jul. 20, 2002
  • Offline.
Forum Stats
Supporter
Level 32
Programmer
Response to Preloader in AS3 May. 14th, 2010 @ 08:48 PM Reply

Hehe no worries.
I'm quite curious why there doesn't seem to be any more elegant solutions to preloaders in AS3 other then loading in another swf. Its quite an important thing to have and creating a hidden frame to pile all mc's and sound clips seemes a bit of a hack fix.

Also:
You might want to disable to right click menu buttons if you have no need for them in your program.

stage.showDefaultContextMenu = false;	// Disable Right click menu

Rewinding and playing could maybe cause the flash to play through frame 2 which could do something funky or break it!

Jynxxx
Jynxxx
  • Member since: May. 5, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to Preloader in AS3 May. 14th, 2010 @ 11:29 PM Reply

Totally agree about AS3 preloaders, I can't believe they're so difficult to manage. And yeah, I've already modified the right-click menu, lol.


BBS Signature