Ultimate Gear War
Join the alien war, prepare your gear and protect your base at all cost!
4.19 / 5.00 15,497 ViewsHey 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!
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!
Dude, you're a genius.
I swear sometimes I think I shouldn't be touching Flash.
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?
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.
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.
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!
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!
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.