Search code examples
actionscript-3getimagesize

How Can know the Size of Image ( Kb) in Action script 3.0?


I am Writing code to load image From Server With a Timer Function Of 2 seconds . I want to know the Size of Each image . Is it Possible to Know in ActionScript 3.0?

enter code here

public class Example extends Sprite {
public function Example() {
 var myTimer:Timer = new Timer(2000);
 myTimer.addEventListener(TimerEvent.TIMER,runMany);
 myTimer.start();
 function runMany(e:TimerEvent):void {
 var loader:Loader=new Loader();
 var url:String= "http:/google.com.example3";
 loader.load(new URLRequest(url));
  addChild(loader);
  }
 }
 }
}

Solution

  • You can use the contentLoaderInfo.bytesTotal property of the Loader class.

    trace(loader.contentLoaderInfo.bytesTotal);
    

    Or you can add an event handler:

    loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    
    function progressHandler(event:ProgressEvent):void
    {
        trace(event.bytesTotal);
    }