Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating a loading screen

New Here ,
Nov 17, 2012 Nov 17, 2012

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.

TOPICS
ActionScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2012 Nov 17, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2012 Nov 17, 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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2012 Nov 17, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2012 Nov 17, 2012

Actually, I figured out another way to get it to work. But thanks for the help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2012 Nov 17, 2012
LATEST

If you found another way you should share it here.  It might prove helpful to someone someday.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2012 Nov 17, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2012 Nov 17, 2012

don't forget to adjust the remiove line to match

this.removeEventListener(Event.ENTER_FRAME,loading);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines