Skip to main content
ExudesAffluence
Participant
November 17, 2012
質問

Creating a loading screen

  • November 17, 2012
  • 返信数 2.
  • 1560 ビュー

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.

このトピックへの返信は締め切られました。

返信数 2

Ned Murphy
Legend
November 18, 2012

don't forget to adjust the remiove line to match

this.removeEventListener(Event.ENTER_FRAME,loading);

kglad
Community Expert
Community Expert
November 18, 2012

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.

ExudesAffluence
Participant
November 18, 2012

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()

Ned Murphy
Legend
November 18, 2012

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.