-
need help with cs3 preloader
hope somebody can help with this. the person who originally created the code has given up and gone back to as2.
after hours of googling i finally found a basic load-bar preloader for cs3 and it works great with the exception of one problem: if the person happens to reload the browser page the flash gets stuck on frame one with a fully loaded preloader bar and it just sits there.
basically you create a mc of the preloader bar (basic rectangle) with dynamic text for the % amount. and it loads up the game and then moves to 2nd frame.
here's the as3 code:
Code:
Select frame 1 on the main timeline, and add this code:
//Import the required assets
import flash.display.*;
//Stop the playhead while loading occurs
this.stop();
//Create a listener to call the loading function as the movie loads
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PL_LOADING);
/*This is the main function, basically it grabs the total and loaded bytes,
calculates a percentage, and displays it by stretching the bar and adjusting
the textfield display. If your bar/textbox instancenames are NOT lbar/lpc,
you'll need to adjust this code to match your instance names*/
function PL_LOADING(event:ProgressEvent):void {
var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
//Stretch the bar
lbar.scaleX=pcent/100;
//Display the % loaded in textfield
lpc.text=int(pcent)+"%";
//If the movie is fully loaded, kick to the next frame on the main timeline
//You may wish to change the gotoAndStop(2) to a gotoAndPlay(2)
if(pcent==100){
this.gotoAndStop(2);
}
}
can anybody tell me why it is getting stuck after refresh?
any help would be greatly appreciated.
thank you!
-coffee
-
i did notice something... if i call up the .swf directly (instead of embedded in html page) this problem does not occur at all.
-
Senior Member
Because it's already loaded in the browser cache, so it's not triggering a PROGRESS event...those are only triggered when a thing gets part of its data but isn't done yet. Instead of checking for progress to be 100%, just create a COMPLETE listener right at the same place you add a PROGRESS listener, and have it call a new function that goes to frame 2...don't put the frame 2 gotoAndPlay call within the PL_LOADING function.
-
thanks for the reply joshstrike... what you say makes sense but unfortunately i'm struggling to understand how to actually implement the change
*sigh*
would it be possible for you to please write out what changes would have to be made for this script to be functional? i feel like such an idiot when it comes to actionscript. i just do not get it no matter how many tutorials or books i read and now with as3 i feel even more lost.
i'd appreciate any help i can get at this point to make this preloader work. i'm a graphic artist not a coder. i can give tips for days regarding photoshop cs3 but this flash cs3 stuff is killing me.
-
Feeling adventurous?
just below:
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PL_LOADING);
add:
this.loaderInfo.addEventListener (ProgressEvent.COMPLETE, PL_COMPLETE);
Remove this:
if(pcent==100){
this.gotoAndStop(2);
}
And add this:
function PL_COMPLETE(event:ProgressEvent):void {
this.gotoAndStop(2);
}
just above:
function PL_LOADING(event:ProgressEvent):void {
And it should work
Also, read up on listeners in flash help (F1)
I don't have a photograph, but you can have my footprints. They're upstairs in my socks.
-
Thanks Tiger : ) Ok, i did a little reading on listeners.
Event listeners let an object receive events broadcast by another object. so i'm telling it to listen for the game to load and listen for it to complete loading right? and if it's complete loading then go to frame 2. and if it's still loading then keep stretching the loader bar until it reaches 100%. is that right?
so this is what i've got:
Code:
import flash.display.*;
this.stop();
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PL_LOADING);
this.loaderInfo.addEventListener (ProgressEvent.COMPLETE, PL_COMPLETE);
function PL_COMPLETE(event:ProgressEvent):void {
this.gotoAndPlay(2);
}
function PL_LOADING(event:ProgressEvent):void {
var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
lbar.scaleX=pcent/100;
lpc.text=int(pcent)+"%";
}
but i'm getting an error on line four that says "1119: Access of possibly undefined property COMPLETE through a reference with static type Class. this.loaderInfo.addEventListener (ProgressEvent.COMPLETE, PL_COMPLETE);"
So does that mean i need to define COMPLETE?
-
Feeling adventurous?
Didn't have flash available when I wrote that, and now that I do, I realize there is no COMPLETE property in ProgressEvent. Instead, we have to use just Event. Here's how it will be instead:
PHP Code:
import flash.display.*;
this.stop();
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PL_LOADING);
this.loaderInfo.addEventListener ([B]Event[/B].COMPLETE, PL_COMPLETE);
function PL_COMPLETE(event:[B]Event[/B]):void {
this.gotoAndPlay(2); // this should maybe be gotoAndStop(2) ?
}
function PL_LOADING(event:ProgressEvent):void {
var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
lbar.scaleX=pcent/100;
lpc.text=int(pcent)+"%";
}
And that should work (I hope)
I don't have a photograph, but you can have my footprints. They're upstairs in my socks.
-
darn... when i preview in flash it works perfectly.
but it's when i get it on an html page it just goes to end of preloader and stops. it does this even before the page is refreshed. the game never even starts. *sigh*
-
anybody else have any ideas?
i'm not ready to throw in the towel yet.
but i'm stumped.... as usual : )
-
Well since I don't have any idea, and I know that you want to use this preload, I suggest u making a button and add a event listener on it so when clicked go to next frame.
Gent
-
would it be possible to create a preloader in as2 and have it load a swf created in as3?
-
I don't know :S. That would be great tho. I would really want that to be possible. As I saw, for some things AS2 is much easier than AS3.
Can anyone answer Coffe plz, I would like to have an answer here.
Gent
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|