MCOBigBen
256 posts
|
Sorry if my mistake is a basic one, they usually are…
I’m trying to make a preloader in a separate scene from my game. I’ve drawn a loading bar, assigned it as “preloader”, and then created this preloader.as:
class preloader extends MovieClip
{
function onEnterFrame()
{
amount = this.getBytesLoaded() / this.getBytesTotal();
preloader._xscale = amount;
if (amount == 1)
{
this.gotoAndStop(2);
}
}
}
The end result is the loading scene and the game flipping back and forth rapidly, and the debug error “The property being referenced does not have the static attribute.”
What am I doing wrong here?
|
|
|
Darty
129 posts
|
the debug error you are getting is because of this line
preloader._xscale = amount;
Change it to
this._xscale = amount;
|
|
|
MCOBigBen
256 posts
|
Thanks! Fixing that (and declaring var amount) gets it to run without any errror messages, but the resulting animation just thrashes back and forth between my preloader scene and the game scene. How do I make it stay on the preloader scene until it’s loaded, and then switch?
|
|
|
Darty
129 posts
|
to sort that you need to add
stop();
before the preloader class
|
|
|
Moonkey
1007 posts
|
and since this class is controlling your preloader, this.gotoAndStop(2); will make your preloader go to frame 2, not your main timeline.
One way to solve that would be changing it to _root.gotoAndStop(2);
|
|
|
MCOBigBen
256 posts
|
Drat, I think I’ve mucked things up. gotoAndStop takes me to a frame (right?), when I’ve actually put the game in a different scene, and not a different frame.
Adding stop(); to the preloader class throws an error. I added stop(); to the Actions panel in the frame, and it doesn’t thrash back and forth, it now starts at the preloader, but the load bar never advances.
|
|
|
Moonkey
1007 posts
|
Drat, I think I’ve mucked things up. gotoAndStop takes me to a frame (right?), when I’ve actually put the game in a different scene, and not a different frame.
You can use gotoAndStop("Scene 2", 1); to go to frame 1 of scene 2. Although gotoAndStop(2) would probably work anyway if Scene 1 is only 1 frame, since all the scenes are essentially just one big timeline.
Its a good idea to use framelabels for stuff like this. Then you can use gotoAndStop(“frame label”) and it’ll work regardless of what scene its in.
but the load bar never advances.
In as2, _xscale is a percentage. It goes up to 100 rather than being a decimal, so your code will only ever fill it to 1% at most.
|
|
|
MCOBigBen
256 posts
|
Ahhh, it’s a percentage in 0-100 form. I was expecting 0-1.0. Thanks, I’ll try that when I get home.
I really appreciate the help Moonkey and Darty!
|
|
|
MCOBigBen
256 posts
|
Baby steps, baby steps….
I added a multiplication by 100 to the calculation of the loading, and now my bar jumps to a bright full green…..and nothing else happens. I tried having the load amount displayed as a dynamic text firled to see if it’s not going all the way to 100, and I’m getting “The class or interface ‘preloaderNumber’ could not be loaded.” I thought I set it up the same way I set up the score dynamic text, but something’s obviously not right.
Can anyone see what I’m doing wrong?
class preloader extends MovieClip
{
var amount;
function onEnterFrame()
{
amount = ((this.getBytesLoaded() / this.getBytesTotal()) * 100);
this._xscale = amount;
_root.preloaderNumber.text = amount;
if (amount == 100)
{
_root.gotoAndPlay("Scene 1");
}
}
}
|
|
|
UnknownGuardian
6220 posts
|
You never defined preloaderNumber. Its probably somewhere else. If its located in the preloader’s movieclip, then I believe you would say this.preloaderNumber.text = amount;
|
|
|
MCOBigBen
256 posts
|
You’re right, I didn’t define it. I was actually throwing the text up as a troublshooting step, but I found Flash’s debug list of variables, so I can see that “amount” is indeed 100.
But _root.gotoAndPlay(“Scene 1”); still isn’t advancing to my actual game, I just get the pre-loader screen forever.
Anybody have an idea of what I’m doing wrong?
|
|
|
Jabor
11382 posts
|
Is “Scene 1” actually a frame label of the part of your game past your preloader?
|
|
|
MCOBigBen
256 posts
|
Scene 1 is the name of the scene which contains the game.
[edit]
OK, I’ve created a frame label for the first (and only) frame of the scene the game is in. I’m now calling the label when the load amount reaches 100%
The result is that now the game thrashes between the preloader and the game again, flickering back and forth.
Previously, Darty recommended adding stop(); “before” the preloader class. I’m a little shaky on how the before and after thing works, and what controls the order. I added the stop(); to the Actions pane of the first (and only) frame of the preloader scene. Is this appropriate, or is this what’s messing me up?
|
|
|
Darty
129 posts
|
you need to add
stop();
at the beginning of every frame. This tells the swf to stop running the main timeline(the 1 containing both your preloader and game frames) until the current frame tells it otherwise(via a gotoAndStop() or gotoAndPlay())
so for example you have added stop(); at the beginning of the preloader frame. and only call the gotoAndPlay() function if amount == 100.
This is essentially saying you dont want to leave the preloader frame until everything is loaded. You also now have a game frame(which you want to stay in until the game is completed) so you will again need to add a stop(); at the beginning of that frame otherwise the main timeline will start running again(which is what is causing the thrashing).
|
|
|
MCOBigBen
256 posts
|
That did it! Awesome, thank you so much!
|
|
|
Stef1987
60 posts
|
I’m also making a preloader, but I’ve done it a bit differently:
the preloader is a seperate class (instead of using the timeline and stuff, I create the preloader object and when it’s loaded, it calls the loaded() function of the game).
But now it only shows the preloader for 1 frame, once it’s completely loaded (and then the next frame the game starts ofcourse).
Before this, I just see the document’s background color (instead of the preloader).
(It’s like it waits for everything to be loaded before it shows anything at all)
Any ideas why this is ?
EDIT: Created separate topic for this question: here
|