Creating a loading screen
Copy link to clipboard
Copied
Yup. I'm not too good at ActionScript. I've only been at it off and on for a week or so.
I'm working on an animation project, but it's gotten really long and complicated, and a good third of the time I try to test it, it lags horrendously, falls out of sync or just freezes. I already have a play button implemented, but that was only enough for so long. I'm working on making a loading screen now. Here's my code - progressBar_mc just a rectangle I'm using to represent the load progress, and percentageLoaded_text is a dynamic text box that I want to show percentage in.
So all of this is on the first frame, and the second frame has a play button, which works without issue. I want the movie to stop on the first frame until it is totally loaded and then go to the second frame, where the viewer can press the play button. I'm not getting any error messages, but the movie just stops on the first frame and doesn't proceed, the bar doesn't change and the text box remains empty.
import flash.events.Event;
stop();
this.loaderInfo.addEventListener(Event.ENTER_FRAME,loading);
function loading(e:Event) {
var total:Number = root.loaderInfo.bytesTotal;
var loaded:Number = root.loaderInfo.bytesLoaded;
var loadProgress:Number = Math.floor((loaded/total)*100);
var loadProgressTxt:String = loadProgress +"%";
progressBar_mc.scaleX = loaded/total;
percentageLoaded_text.text = loadProgressTxt;
if (total == loaded) {
gotoAndStop(2);
this.loaderInfo.removeEventListener(Event.ENTER_FRAME,loading);
}
}
If there's any more questions or if you need screen shots or anything, I'll get on that.
Copy link to clipboard
Copied
the LoaderInfo class doesn't have an enter frame event. use;
import flash.events.Event;
stop();
this.addEventListener(Event.ENTER_FRAME,loading);
function loading(e:Event) {
var total:Number = this.loaderInfo.bytesTotal;
var loaded:Number = this.loaderInfo.bytesLoaded;
var loadProgress:Number = Math.floor((loaded/total)*100);
var loadProgressTxt:String = loadProgress +"%";
progressBar_mc.scaleX = loaded/total;
percentageLoaded_text.text = loadProgressTxt;
if (total == loaded) {
this..removeEventListener(Event.ENTER_FRAME,loading); // <- thank you ned, for the correction.
gotoAndStop(2);
}
}
p.s. please mark helpful/correct responses.
Copy link to clipboard
Copied
When I change that, I get output errors. I've looked through, and I can't find what it can't reference.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at piano_fla::MainTimeline/loading()
Copy link to clipboard
Copied
Go into your Flash publish settings and select the option to Permit Debugging. That should help by identifying which line is causing the error in the error message.
Copy link to clipboard
Copied
Actually, I figured out another way to get it to work. But thanks for the help!
Copy link to clipboard
Copied
If you found another way you should share it here. It might prove helpful to someone someday.
Copy link to clipboard
Copied
(kglad... you're welcome... as usual, you beat me to the punch by a few minutes while I was testing what I was going to offer, so I figured I'd just add the other adjustment before it became a new error)
Copy link to clipboard
Copied
don't forget to adjust the remiove line to match
this.removeEventListener(Event.ENTER_FRAME,loading);

