Varilian
92 posts
|
The title says it all.
When I start my game up on my pc, it loads to 100%. shows the correct loaded/total bytes, and the animation works.
When I upload it to SWFCabin, I get infinite %, and 0 bytes to load.
I tried adding:
if(toLoad==0)
{
toLoad=1;
}
To the code, but to no avail.
Full code, all children/dynamic textfields are appropriately named.
stop();
stage.addEventListener(Event.ENTER_FRAME, loader);
nextBtn.tabEnabled=false;
nextBtn.addEventListener(MouseEvent.MOUSE_UP,clicking);
function clicking(e:MouseEvent)
{
gotoAndPlay(2);
}
function loader(e:Event):void
{
var toLoad:Number = stage.loaderInfo.bytesTotal;
var loaded:Number = stage.loaderInfo.bytesLoaded;
var total:Number = loaded/toLoad;
if(toLoad==0){toLoad=1;}
if(loaded >= toLoad)
{
preloader.gotoAndStop(Math.floor(total*100));
preloader.percentBytes.text=Math.floor(total*100) + "%";
preloader.currentBytes.text=""+loaded;
preloader.totalBytes.text =""+toLoad;
removeEventListener(Event.ENTER_FRAME, loader);
nextBtn.x=275;
}
else
{
preloader.gotoAndStop(Math.floor(total*100));
preloader.percentBytes.text=Math.floor(total*100) + "%";
preloader.currentBytes.text=""+loaded;
preloader.totalBytes.text =""+toLoad;
}
}
All objects are set to export on frame 2.
Thanks as usual!
|
|
|
UnknownGuardian
6220 posts
|
Why are you doing this: if(toLoad==0){toLoad=1;} when toLoad is already initialized?
And why do you have preloader.gotoAndStop(Math.floor(total*100)); Do you have 100 frames?
|
|
|
XxPsychoFadexX
950 posts
|
Duplicate your preloader, fill it in with a colour that you like, convert it to movie clip and give it an instance name of “preloaderFill”.
Then enter the following code:
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);
gotoAndStop(2);
} else {
preloader.preloaderFill.scaleX = total;
preloader.percentBytes.text = Math.floor(total*100) + "%"
}
}
I think that should do it. Tell me if this doesn’t work.
|
|
|
Cantor
78 posts
|
Why are you using an ENTER_FRAME event type? I have never used that to make a preloader, i have always used the ProgressEvent type and never had any trouble with them.
Try using:
stop();
loaderInfo.addEventListener(ProgressEvent.PROGRESS, loader);
function loader(filename:ProgressEvent):void
{
//find the file size and convert it to a 1-100% number
var percent:Number = Math.floor((filename.bytesLoaded*100) /filename.bytesTotal);
//go to the frame number based on the percent loaded
if(percent <=99)
{
preloader.gotoAndStop(percent);
}//end of if
//when fully loaded go to the last perloader frame and remove the listener
else if(percent == 100)
{
preloader.gotoAndStop(percent);
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loader);
nextBtn.x = 275;
}//end of else if
};
That should work. As i said, it never fails for me.
|
|
|
Varilian
92 posts
|
Originally posted by Cantor:
Why are you using an ENTER_FRAME event type? I have never used that to make a preloader, i have always used the ProgressEvent type and never had any trouble with them.
Try using:
stop();
loaderInfo.addEventListener(ProgressEvent.PROGRESS, loader);
function loader(filename:ProgressEvent):void
{
//find the file size and convert it to a 1-100% number
var percent:Number = Math.floor((filename.bytesLoaded*100) /filename.bytesTotal);
//go to the frame number based on the percent loaded
if(percent <=99)
{
preloader.gotoAndStop(percent);
}//end of if
//when fully loaded go to the last perloader frame and remove the listener
else if(percent == 100)
{
preloader.gotoAndStop(percent);
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loader);
nextBtn.x = 275;
}//end of else if
};
That should work. As i said, it never fails for me.
If I have to, I will use that. But for some reason, I switched to using a preloader in a different scene, and the problem fixed itself.
|
|
|
XxPsychoFadexX
950 posts
|
Why are you using an ENTER_FRAME event type?
I find this type of code easier. Both are correct though. :)
|
|
|
rarapompoms
184 posts
|
Originally posted by xxXPsychoFadeXxx:
Why are you using an ENTER_FRAME event type?
Both are correct though. :)
Says who? You should use the most appropriate event available, which would be the progress event.
|
|
|
Cantor
78 posts
|
Indeed, though the reason i don’t use the enter frame event type is because i haven’t ever seen it used before. But if the code is working now then just use the code you know :)
|
|
|
KMAE
439 posts
|
I tried the progress event and it didn’t work for me. Why are you going to “percent”? Are you using multiple frames for this?
|
|
|
rarapompoms
184 posts
|
The preloader will be a movie clip with a hundred frames in it. It will probably be something like a progress bar, and in each frame the bar will be a little bigger. Unless the preloader is a really complex animation it’s probably better to do it with the drawing api.
|
|
|
XxPsychoFadexX
950 posts
|
Says who? You should use the most appropriate event available, which would be the progress event
In case you haven’t realised, we’re suggesting different solutions. The ProgressEvent is correct, but the ENTER_FRAME is also correct.
|
|
|
rarapompoms
184 posts
|
That wasn’t a reply, you just reworded your previous statement.
|
|
|
XxPsychoFadexX
950 posts
|
Originally posted by rarapompoms:
That wasn’t a reply, you just reworded your previous statement.
Interesting.
Originally posted by rarapompoms:
Originally posted by xxXPsychoFadeXxx:
Why are you using an ENTER_FRAME event type?
Both are correct though. :)
Says who? You should use the most appropriate event available, which would be the progress event.
So, was your post a valid reply either?
|
|
|
rarapompoms
184 posts
|
Which post? The one you quoted? Yes, it was a valid reply. It was a contention to your statement that both events are correct for the situation discussed.
|
|
|
KMAE
439 posts
|
I would much rather use the scaleX property to make my box a little bit bigger on each enter frame than to use so many frames.
|
|
|
SuperFalconKick
98 posts
|
Even better would be to use the drawing API so your preloader is as small as possible. Although if your preloader is a really complex animation you’ll probably have to do it through frames.
|