Stef1987
60 posts
|
I have never made a preloader before, so I thought I’d make one (even if it only takes 1 sec to load).
I prefer to make stuff hapen via .as files, rather than scripting it in the flash file.
So instead of the preloader being on the first frame of the game, I made it so the game creates a preloader object (which I attach to the game), which then calls the loaded() function of the game when fully loaded (which starts the actual game, and removes the preloader).
Now when I test this, instead of seeing the preloader, I see completely nothing, until the game is loaded, then I see the preloader for 1 frame, and then the game starts.
(It’s like the swf waits for everything to be loaded before it shows anything at all)
Any ideas why this is ?
(I vaguely remember reading something about that you first have to do something so the swf starts playing before all content is loaded. If this is true, then I guess that’s the problem.)
|
|
|
DeepClaw
549 posts
|
(It’s like the swf waits for everything to be loaded before it shows anything at all)
That’s true…. if you have only ONE frame. Thats why you should put your preloader into the first frame and anything else into the second. That way flash will launch the preloader after the first frame is ready.
|
|
|
XxPsychoFadexX
950 posts
|
It’s what DeepClaw said. But it can also be a coding problem. So let’s say that you’ve named your variables to “toLoad” <— bytes left and “loaded” <— bytes loaded. Your vars should look like this
var toLoad:Number = loaderInfo.bytesTotal;
var loaded:Number = loaderInfo.bytesLoaded;
After that, the proccess is pretty simple:
if(toLoad == loaded) {
removeEventListener(Event.ENTER_FRAME, loaderF);
gotoAndStop(*);
}
considering that your eventListener looks like this:
addEventListener(Event.ENTER_FRAME, loaderF);
Hope this helped.
|
|
|
Stef1987
60 posts
|
EDIT: this post is a reaction on DeepClaw’s post (xxXPsychoFadeXxx post wasn’t there yet)
so there’s no other way but to write the code in the “Actions – Frame” window, instead of in the document’s class .as file ?
and exactly what do you mean by putting “everything else in the second frame” ?
Do you mean that all of the code of the document class has to be there instead of in the as file ?
and do I have to change the publish setting so it only loads the as files in 2nd frame (or keep it on the first) ?
|
|
|
XxPsychoFadexX
950 posts
|
and exactly what do you mean by putting “everything else in the second frame” ?
What he basically means is that all your code about the preloader must be at the first frame.
|
|
|
Stef1987
60 posts
|
xxXPsychoFadeXxx, that’s pretty much what I have
function loading(e:Event)
{
var total:Number = this.stage.loaderInfo.bytesTotal;
var loaded:Number = this.stage.loaderInfo.bytesLoaded;
bar.scaleX = loaded/total;
percent.text = Math.floor((loaded/total) * 100)+ “%”;
trace((loaded/total) * 100);
if (total >= loaded)
{
removeEventListener(“enterFrame”, loading);
Game.instance.removeChild(this);
Game.instance.Loaded();
}
}
but I guess the problem is the way everything is beeing loaded, if someone can give me more info on how that all works, that would be helpfull.
|
|
|
XxPsychoFadexX
950 posts
|
What I would use:
stop();
addEventListener(Event.ENTER_FRAME, loaderF);
function loaderF(e:Event):void {
var toLoad:Number = loaderInfo.bytesTotal;
var loaded:Number = loaderInfo.bytesLoaded;
var total:Number = loaded/toLoad;
if(loaded == toLoad) {
removeEventListener(Event.ENTER_FRAME, loaderF); // if loaded equals to toLoad remove the event listener
gotoAndStop(2);
} else {
preloader.preloaderFill.scaleX = total; // move your fill colour to the right
preloader.percentBytes.text = Math.floor(total*100) + "%" // round the percentage of loaded bytes
}
}
preloader <— My preloader movieclip
percentBytes <— The percentage of the bytes loaded
toLoad <— All the bytes in total
loaded <— The bytes loaded
|
|
|
Stef1987
60 posts
|
yeah alright, but that’s not really the problem is it
the code of how the loading-bar fills and starting the game when it’s all loaded, that all works
and I actually moved the code from the preloader to the fisrt frame of the game, but still works as before; nothing is done until it’s all loaded.
the code of the first frame only begins when everything is already loaded
|
|
|
XxPsychoFadexX
950 posts
|
What do you excactly mean? You can’t see the preloader?
|
|
|
Wordblind
1053 posts
|
Originally posted by xxXPsychoFadeXxx:
and exactly what do you mean by putting “everything else in the second frame” ?
What he basically means is that all your code about the preloader must be at the first frame.
And everything you don’t want loaded before the preloader starts must be in a later frame.
|
|
|
DeepClaw
549 posts
|
so there’s no other way but to write the code in the “Actions – Frame” window, instead of in the document’s class .as file ?
You still can write it in “document class”.
Sounds like you use Flash CS. There is a setting “publish into first frame”. Uncheck this setting to ALL of your stuff but preloader.
the code of the first frame only begins when everything is already loaded
That’s because ALL your stuff is in the first frame.
Flash only execute the first frame, if it is fully loaded. If your game has only one frame, then flash will wait until your whole game is loaded.
|
|
|
Stef1987
60 posts
|
yeah but “everything else” is in seperate .as files, so I don’t get how I put that in the 2nd frame
I tried changing the settings so it only loads the as files on frame 2, but that doesn’t seem to change anything
|
|
|
rarapompoms
184 posts
|
Just get FlashDevelop. Project>New Project>AS3.0 with Preloader>Done
|
|
|
XxPsychoFadexX
950 posts
|
I don’t know if that’s your problem but you can press Ctrl + Enter once you’re testing the movie to simulate the download.
|
|
|
Stef1987
60 posts
|
Originally posted by DeepClaw:
so there’s no other way but to write the code in the “Actions – Frame” window, instead of in the document’s class .as file ?
You still can write it in “document class”.
Sounds like you use Flash CS. There is a setting “publish into first frame”. Uncheck this setting to ALL of your stuff but preloader.
Ah, so that’s what I vaguely remembered
Originally posted by Stef1987: …
(I vaguely remember reading something about that you first have to do something so the swf starts playing before all content is loaded. If this is true, then I guess that’s the problem.)
and yeah I use flash cs3, should I have mentioned that :s
I thought flash cs3 or 4 is what most people use ?
|
|
|
DeepClaw
549 posts
|
I thought flash cs3 or 4 is what most people use ?
That’s right!
But most people don’t like coding. They prefer drawing the most stuff and animate it using the timeline.
Flash CS isn’t suitable for coding.
|
|
|
XxPsychoFadexX
950 posts
|
Originally posted by xxXPsychoFadeXxx:
I don’t know if that’s your problem but you can press Ctrl + Enter once you’re testing the movie to simulate the download.
Please look at that.
|
|
|
virror
267 posts
|
The biggest reason Flash CS isn’t suited for coding is the crappy coding environment.
|
|
|
rarapompoms
184 posts
|
Originally posted by virror:
The biggest reason Flash CS isn’t suited for coding is the crappy coding environment.
Thanks mr obvious
|
|
|
Stef1987
60 posts
|
I know about the ctrl+enter thing xxXPsychoFadeXxx, that’s how I’m testing it, so that’s not the problem
Originally posted by DeepClaw:
I thought flash cs3 or 4 is what most people use ?
That’s right!
But most people don’t like coding. They prefer drawing the most stuff and animate it using the timeline.
Flash CS isn’t suitable for coding.
then what to use ? Flex ?
I don’t have that (which is weird, as I should have the master collection, isn’t flex part of that ?)
but anyway, I unchecked all the “export in frame 1” boxes (except for the preloader), but now I get tons of errors in 1 as file (I think it’s just the first file it wants to export)
basically all the errors are that it doesn’t know all the movieclips for which I unchecked “export in frame 1”
any ideas ? :s
|
|
|
Wordblind
1053 posts
|
I find these two lines particularly interesting:
Game.instance.removeChild(this);
Game.instance.Loaded();
Correct me if I am wrong, but it looks like the Game.Loaded function is going to be doing something interesting in later frames. If the Game class references a lot of stuff from the later frames, they would all have to be loaded before the preloader would start.
Edit:
basically all the errors are that it doesn’t know all the movieclips for which I unchecked “export in frame 1”
Yeah, that was your problem. Your preloader should be independent of all that stuff.
|
|
|
XxPsychoFadexX
950 posts
|
Originally posted by Stef1987:
I know about the ctrl+enter thing xxXPsychoFadeXxx, that’s how I’m testing it, so that’s not the problem
No, you didn’t understand. Press Ctrl + Enter after you’ve accessed the testing screen. [Like, press Ctrl + Enter to open the testing windows and press Ctrl + Enter again] Or you can do this:
View >> Simulate Download. And see what happens.
Also try replacing your code with the code I gave you earlier. Just make sure you rename the movie clips appropriately.
|
|
|
Stef1987
60 posts
|
Originally posted by Wordblind:
I find these two lines particularly interesting:
Game.instance.removeChild(this);
Game.instance.Loaded();
Correct me if I am wrong, but it looks like the Game.Loaded function is going to be doing something interesting in later frames. If the Game class references a lot of stuff from the later frames, they would all have to be loaded before the preloader would start.
yeah, I know, that isn’t really good coding
(in the game constructor, i put the static var instance = this, so it should be ok though I think)
I don’t really know what you mean after that, but in any case, I don’t have any code in any frame at all. it’s all in as files
and the game movieclip only has 1 frame (I changed it all back to the way it was before I started this topic, as it seemed like the problem was the “export in first frame” thing)
(but basically, the game loaded function is what starts the whole game)
|
|
|
Stef1987
60 posts
|
Originally posted by xxXPsychoFadeXxx:
Originally posted by Stef1987:
I know about the ctrl+enter thing xxXPsychoFadeXxx, that’s how I’m testing it, so that’s not the problem
No, you didn’t understand. Press Ctrl + Enter after you’ve accessed the testing screen. [Like, press Ctrl + Enter to open the testing windows and press Ctrl + Enter again] Or you can do this:
View >> Simulate Download. And see what happens.
Also try replacing your code with the code I gave you earlier. Just make sure you rename the movie clips appropriately.
No I do understand
that’s what I meant, I press ctrl+enter once the swf has started,
if I don’t, then the loading takes no time at all.
|
|
|
Stef1987
60 posts
|
Originally posted by Wordblind:
Edit:
basically all the errors are that it doesn’t know all the movieclips for which I unchecked “export in frame 1”
Yeah, that was your problem. Your preloader should be independent of all that stuff.
What do you mean ?
How is the preloader not independent of all those movieclips ?
anyway, I’m hungry, I’ll be back later
|