Copy link to clipboard
Copied
Hi, I'm trying to make a web site, I have 7 scenes and everything is working perfect. But here's my question.
When I try to make 1st scene as a preloader nothing happens. Preloader never shows up and it jumps directly to 2nd scene "Main"
Here's my code:
stop();
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(e:Event):void {
var total:Number = this.stage.loaderInfo.bytesTotal;
var loaded:Number = this.stage.loaderInfo.bytesLoaded;
bar_mc.scaleX = loaded/total;
loader_txt.text = Math.floor((loaded/total)*100)+ "%";
if (total == loaded) {
gotoAndPlay(1,"Main");
this.removeEventListener(Event.ENTER_FRAME, loading);
}
}
Also if I delete my contents in the "Main" scene and leave a single image, code works perfect.
Preloader shows up and then loads my "Main" scene.
How can I code it, as it first calculates my whole scenes, and shows my 1st scene "preloader" at the beginning.
Those two lines have periods where there should be commas...
...(ProgressEvent.PROGRESS, loop);
...(Event.COMPLETE, done);
Copy link to clipboard
Copied
You should try creating the preloader as a separate file and load your web site file into that. Here is a link to a tutorial....
Copy link to clipboard
Copied
I followed the tutorial, here's the code he suggested.
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS. loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE. done);
l.load(new URLRequest("main.swf"));
function loop(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
percent.text = Math.ceil(perc*100).toString();
}
function done(e:Event):void
{
removeChildAt(0);
percent = null;
addChild(l);
}
When I try to export this, flash gives me an error with line 2 and line 3.
Copy link to clipboard
Copied
What are the complete error messages?
Copy link to clipboard
Copied
Scene 1, Layer 'actions', Frame 1, Line 2 | 1119: Access of possibly undefined property loop through a reference with static type String. |
Scene 1, Layer 'actions', Frame 1, Line 2 | 1136: Incorrect number of arguments. Expected 2. |
Scene 1, Layer 'actions', Frame 1, Line 3 | 1119: Access of possibly undefined property done through a reference with static type String. |
Scene 1, Layer 'actions', Frame 1, Line 3 | 1136: Incorrect number of arguments. Expected 2. |
Copy link to clipboard
Copied
Those two lines have periods where there should be commas...
...(ProgressEvent.PROGRESS, loop);
...(Event.COMPLETE, done);
Copy link to clipboard
Copied
thanks that solved the problem
Copy link to clipboard
Copied
You're welcome