[ALMOST SOLVED] Preloader Problems

Subscribe to [ALMOST SOLVED] Preloader Problems 14 posts

Sign in to reply


 
avatar for suecityvokills suecityvokills 30 posts
Flag Post

I’m sure this problem has been solved before but I would like some 1 on 1 help with this as I go along.

So I’ve created a PreLoader for my game. Everything was working great until I did this. I came across various problems as I went along and solved most of them on my own but have reached a point where I’m just about ready to give up (its a good thing I’m pretty excited about this game.. otherwise i would).

Problem 1a: the preloader wasn’t appearing until everything was loaded.
I solved this by turning on the bandwidth profiler to find that everything was loading in the same frame.

Problem 1b: all my MovieClips were loading in the first frame (the preloader frame).
I solved this by going through all the individual movie clips and turning off the default setting of “Load in first frame”.

Problem 1c: all my classes were loading in the first frame (the preloader frame).
I solved this problem by going to File>PublishSettings>AS2Settings and setting export frame for classes to 2.

Problem 2: MovieClips that I brought into my game with _root.attachMovie that are in my library never appear during the game.
I solved this problem by placing an instance of these MovieClips on frame 2 off of the stage so that they are not visible (it was clear that because the clip was being loaded past the first frame it wasn’t being loaded at all).

Problem 3 (the current problem): These off-stage ‘extra’ instances of the same MovieClip are looping and causing various problems with the legitimate MovieClip instances. Variables that are set to add +1 on a per MovieClip basis are being altered by the original off stage ‘extra’ instance.

for example, in this code:
Main.as:

if (var>2) {_root.attachMovie(“Problem” , “Problem” + _root.getNextHighestDepth() , _root.getNextHighestDepth())}

Problem.as:
class Problem extends MovieClip {
var timer;
function onLoad() {
timer = 0;
}
function onEnterFrame() {
timer += 1;
}

timer is being manipulated by both the off-stage “extra” instance AND the actual wanted instance (which increases later). timer starts adding immediately when the 2nd frame loads because of the off-stage instance… should I be using this.timer instead? how would that look with the previous code?

I can’t figure this out but I am definitely prepared for a much needed forehead slap.

On a side note I feel like there HAS to be a better way to go about incorporating MovieClips into a game while using _root.attachMovie with a preloader. The approach of placing off-stage instances in frame 2 just seems… redundant.. and probably adds unneeded lag to a game.

I also feel like there HAS to be a better way in general to incorporate a preloader into a game without having to; add in a first frame, move everything to the second frame, and change the publishing settings for classes to frame 2.

Thanks in advance for any help, advice, or direction you can offer!!

 
avatar for Moonkey Moonkey 1007 posts
Flag Post

Unfortunately, the way you are doing it IS the best way to preload stuff in as2.

Placing instances of all your MovieClips on frame 2 is the right thing to do, but your playhead should never actually go to frame 2. Once you’re all loaded up, go to frame 3 instead and start your game there.

 
avatar for suecityvokills suecityvokills 30 posts
Flag Post

ahhh ic frame 3 is the “Game Frame”. 2 is the attachMovie Frame and 1 is the Preloader. It works great now.
If i wanted to load up a sound file would I put it in a MovieClip and load that in Frame 2 as well? thanks a ton for your help!

 
avatar for jonathanasdf jonathanasdf 3835 posts
Flag Post

and if you’re not going to frame 2, the enterFrame events for your offscreen Problem won’t run, and you won’t have the problem.

Still, unless you declared the timer as static or _root.timer, I fail to see how both of the clips can affect the same timer..

 
avatar for ssjskipp ssjskipp 258 posts
Flag Post

The best way I’ve seen to fix this is to do it like so:
1. Frame 1 contains your preloader
2. Frame 2 contains a symbol called ‘Assets’
[Inside the ‘Assets’ Symbol]
1. Frame 1 has a simple graphics, like a rectangle with the word “ASSETS” on it
2. Frame 1 also has a stop(); action
3. Frame 2 of ‘Assets’ contains all export-via-actionscript from the library
4. Create a new layer for each Sound that you’re exporting via actionscript, and set them to Event.

When loading is complete, skip frame 2 and go directly to frame 3, which is where everything for your game picks up.
That should do it. That way, frame 2 of assets will load AFTER frame 1, which is the pre-loader.
Not only does it fix all preloader problems, but it also fixes the issue of conflicting scripts in symbols.

 
avatar for Livett Livett 161 posts
Flag Post

That is how I originally had my preloader. However, I was told by… possibly jonathanasdf (if it was you then why haven’t you told this person? :P) that you can change the “Export to Frame 1” check box to “Export to Frame 2”. To do this go to File > Publish Settings > ‘Flash’ tab and then next to actionscript there is a button saying, ‘Settings’, click that and change export to frame 2 rather than frame 1.

Then what you need to is set everything (except your preloader MC’s) to export to frame 2, add a ‘stop()’ on the timeline in frame 1, and then once your preloader completes the loading, skip to frame 2.

This gets rid of the need of placing instances of all the MC’s on the timeline except for your preloader. So for your preloader, (in my case just a bar and text), place them on the stage, give them an instance name each and then manipulate them that way rather than addChild().

 
avatar for suecityvokills suecityvokills 30 posts
Flag Post

That’s how i had it before when it didn’t work i think, I believe that option applies to class’ and not movieclips (at least in AS2 ).
How do I “set everything (except your preloader MC’s) to export to frame 2”? Is this in AS or a checkbox similar to the “Export in frame 1” for MCs?

Also just out of curiosity do people wrap a child game.swf with a parent preloader.swf anymore? Of course I would need to host two swf’s then.. but it’s still better than this current rediculous rig. unless there is something unforeseen and bad about doing it that way.

Found that idea at http://www.actionscript.org/forums/archive/index.php3/t-67564.html

 
avatar for suecityvokills suecityvokills 30 posts
Flag Post

.. and for all this trouble and “ugly programing” all Adobe would need to do is add in a “Export in custom frame [ ]” under MC linkage. problem solved. This would greatly help people to easily incorporate preloaders throughout their FlashApp/Game.. and make it sooo easy to have multiple preloaders in an App.

 
avatar for Moonkey Moonkey 1007 posts
Flag Post

.. and for all this trouble and “ugly programing” all Adobe would need to do is add in a “Export in custom frame [ ]” under MC linkage.

I believe that was added in cs4, and is what Livett is talking about. Not sure if it’s available for as2 projects, though.

Having a wrapper swf is fine if you only want to distribute your game to Kong, but if you want to upload to multiple sites its out of the question really.

 
avatar for jonathanasdf jonathanasdf 3835 posts
Flag Post

yes it is CS4 only, and yes it applies to as2, and all versions of flash player.

And, it doesn’t only apply to classes. If you try it with the bandwidth limit settings you’ll see that it works properly.

Having a wrapper swf is not definitely out of the question. If you can find a server with a good bandwidth to host it you can do that and still upload to many sites. Or if it’s a site like kong and you can upload additional files, it works, if you don’t want to worry about spreading it across the internet.

 
avatar for suecityvokills suecityvokills 30 posts
Flag Post

Ahh I see, well it does work with the previous help although it isn’t as “clean” as I’d like and I think Ill go the rout of a single contained swf. Looks like I’ll have to upgrade to CS4/AS3 sooner rather than later! :)

Thanks a lot for the much needed help guys!

 
avatar for suecityvokills suecityvokills 30 posts
Flag Post
Originally posted by ssjskipp:

4. Create a new layer for each Sound that you’re exporting via actionscript, and set them to Event.

Hey new problem:
I would set all my sounds to Event but I read:

Found at adobe.com:


Use sounds set to Stream for only that content which absolutely must synchronize with the timeline, such as spoken words which are lip-synched.

Unfortunately this is the case for some sound in my game. How do I load up a streaming sound to be used in the game on frame 2 in assets?

 
avatar for ssjskipp ssjskipp 258 posts
Flag Post

no no no, you put the sounds that are used in ActionScript (Export via ActionScript) in the Assets MC so they load on frame 2, not frame 1.

In your game/movie, you can use sounds however.

 
avatar for suecityvokills suecityvokills 30 posts
Flag Post

New questions;

In the fla would I then drag the .mp3 from my library to a new layer in the 2nd assets frame?
oh and how do I switch a sound file between event and stream?

Sign in to reply