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

Show progress through AC3

New Here ,
May 13, 2009 May 13, 2009

Hi

I've been having a hard time for some days now trying to make a progressbar in AC3. I searched the web and tried several different approaches and attempts but nothing works.

I hope I can get some input from here now...

The main portion of the applicataion is working. It's only when I try to use AC3 to control the jumps in the timeline the problem occours.

This is my AC3-code:

import flash.events.*;
import flash.display.Loader;
stop();
addEventListener(Event.ENTER_FRAME, myFunction);
var p_loader:URLLoader=new URLLoader();
//addChild(p_loader);


function myFunction(evt:Event){
    kirupatxt.text = "TESTING";
    removeEventListener(Event.ENTER_FRAME,myFunction);
    var bytes = p_loader.bytesTotal;//evt.bytesTotal();
   trace("bytes_total: "+ bytes);
   trace("inside 'myFunction' in Preloader 1");
    var bytes_loaded = p_loader.bytesLoaded;
   trace("bytes_loaded: "+ bytes_loaded);
    if (bytes_loaded == bytes){
        kirupatxt.text = "movie loaded";
        gotoAndPlay("scene1");
   trace("inside 'myFunction' in Preloader 5");
    }else{
        this.kirupatxt.text = "loading (" + bytes_loaded + "/" + bytes +")";
        gotoAndStop("preloader");
    }

As I run the code all the trace-statements is printed. But the bytes is 0 all the time. I guess this has something to do with the main problem. I tried to simulate the download-process, but in this way not even the "kirupatxt.text = "TESTING";" is printed in my dynamic textfield.

As my cody shows I've been trying to solve the problem in different ways of debugging.

If somebody is able to provide some help here I'd be VERY thankfull!

Thanks in advance.

TOPICS
ActionScript
1.0K
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
Guest
May 13, 2009 May 13, 2009

You should be working with a LoaderInfo object -- not a URLLoader

Change

var p_loader:URLLoader = new URLLoader();

to

var p_loader:LoaderInfo = this.loaderInfo;

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 ,
May 14, 2009 May 14, 2009

Ah, yes of course. Briliant! Thanks a lot 😉

Now I get something printed to the screen during a simulated download.

I have 2 different problems, though.

I thought that p_loader should be added to the scene? But if I do that an error is produced. Is that because the variable only should be added if it's a graphical item in the display?

The last thing is that although my application aparently works as intended now then I still get an error (several times) during run. The error is:


TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at projectName_fla::MainTimeline/myFunction()

I have no idea why this error occours. All the function does is to print the load-information from the LoaderInfo - which works. After that the scene jumps to another place in the timeline - which works correctly, too. To debug the function I put ":void" after the function but that didn't have any effect at all.

Ah, I just tried the "Debug->Debug Movie" and it turns out that the error is produced in the line:

this.kirupatxt.text = "initializing";

as I expected. Howcome this line produces an error while the line does not produce an error if the simulated download is in progress? And howcome this line keeps on producing several instances of the error even when the active area changes to a completely different place in the timeline?

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
Guest
May 14, 2009 May 14, 2009

Once loading is complete, you need to stop handling the ENTER_FRAME event. Using the code from your original post:

function myFunction(evt:Event){
    kirupatxt.text = "TESTING";
    removeEventListener(Event.ENTER_FRAME,myFunction);
    var bytes = p_loader.bytesTotal;//evt.bytesTotal();
   trace("bytes_total: "+ bytes);
   trace("inside 'myFunction' in Preloader 1");
    var bytes_loaded = p_loader.bytesLoaded;
   trace("bytes_loaded: "+ bytes_loaded);
    if (bytes_loaded == bytes){
        kirupatxt.text = "movie loaded";

        // remove the event listener before going to another frame

        removeEventListener(Event.ENTER_FRAME, myFunction);
        gotoAndPlay("scene1");
   trace("inside 'myFunction' in Preloader 5");
    }else{
        this.kirupatxt.text = "loading (" + bytes_loaded + "/" + bytes +")";
        gotoAndStop("preloader");
    }
}

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
Guest
May 14, 2009 May 14, 2009
LATEST

Oops! You already had a removeEventListener in the function.

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