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

passing variables with "ProgressEvent.PROGRESS"

Guest
Aug 30, 2013 Aug 30, 2013

Hi all, i have this code:

imgContainer.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, function(){loadProgress(loader)});

function loadProgress(aa):void{

          var percentLoaded:Number = Math.round((event.bytesLoaded/event.bytesTotal) * 100);

          trace("Loading: "+percentLoaded+"%");

          percentCar=percentLoaded*3;

  aa.width=percentCar;

          aa.x=-percentCar/2;

}

but doesnt work because of in this way in loadProgress there's no event to calculate bytesLoaded ecc...

how can i pass variables in this formula?

thanks a lot

TOPICS
ActionScript
774
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

correct answers 1 Correct answer

Community Expert , Aug 30, 2013 Aug 30, 2013

use:

imgContainer.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS , loadProgress);

function loadProgress(event:ProgressEvent):void{

          var percentLoaded:Number = Math.round((event.bytesLoaded/event.bytesTotal) * 100);

          trace("Loading: "+percentLoaded+"%");

          percentCar=percentLoaded*3;

loader.width=percentCar;

         loader.x=-percentCar/2;

}

or, if there's some really good reason to pass loader into your loadProgress function use:

imgContainer.contentLoaderInfo.addEven
...
Translate
Community Expert ,
Aug 30, 2013 Aug 30, 2013

use:

imgContainer.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS , loadProgress);

function loadProgress(event:ProgressEvent):void{

          var percentLoaded:Number = Math.round((event.bytesLoaded/event.bytesTotal) * 100);

          trace("Loading: "+percentLoaded+"%");

          percentCar=percentLoaded*3;

loader.width=percentCar;

         loader.x=-percentCar/2;

}

or, if there's some really good reason to pass loader into your loadProgress function use:

imgContainer.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, function(e:ProgressEvent) {

  loadProgress(e,loader)

});


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
Aug 30, 2013 Aug 30, 2013

but in this way the variable "loader" doesnt't pass into loadProgress ?!?

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 ,
Aug 30, 2013 Aug 30, 2013

there's no reason to do that but if you think you know better, use:

imgContainer.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, function(e:ProgressEvent) {

  loadProgress(e,loader)

});

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
Aug 30, 2013 Aug 30, 2013

thanks a lot, really helpful!

have a nice week-end!

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 ,
Aug 30, 2013 Aug 30, 2013
LATEST

you're welcome.

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