开发者

ActionScript 3: ProgressEvent's bytesLoaded property to Document Class

开发者 https://www.devze.com 2022-12-10 19:09 出处:网络
in AS3, I have an external class ImageLoader, that loads an image upon request. In that class, I have an event handlers:

in AS3, I have an external class ImageLoader, that loads an image upon request. In that class, I have an event handlers:

ImageLoader Class

public function loadImg(path:String):voi开发者_运维百科d
{
 ldr = new Loader();
 ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, getProgress);
 var req:URLRequest = new URLRequest(path);
 ldr.load(req);
}

private function getProgress(e:Event):void
{
 dispatchEvent(new Event("PROGRESS_INFO"));
}

I am trying to send the download progress updates back to the main Document Class and display it on screen, so I am trying to dispatch the event "PROGRESS_INFO" and then get the information from the passed Event Object, like so:

Document Class

private function getProgressInfo(e:Event):void
{
 trace(e.target.bytesTotal);
}

This however, is proving futile... any ideas on how I can get the progress info out of the IMageLoader class?

note: I know I can add bytesLoaded & bytesTotal to a public variable, but then I won't get the benefit of seeing the bytesLoaded property update in the ProgressEvent class. Any ideas?


Make sure your ImageLoader class extends the EventDispatcher class. Also, instead of creating a new event, you should re-dispatch the ProgressEvent.

private function getProgress(e:ProgressEvent):void
{
 dispatchEvent(e);
}

This should work in the document class:

myImageLoader = new ImageLoader();
myImageLoader.addEventListener(ProgressEvent.PROGRESS, getProgressInfo);

private function getProgressInfo(e:ProgressEvent):void
{
 trace(e);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消