/ Published in: ActionScript 3
intialize it like:
var newLoader: ImageLoader(); newLoader.load( image_url.jpg ) ; if (newLoader.progress == 100 ) { addChild ( newLoader.newLoader.content as Bitmap ); }
Its in a very basic form, best to dispatch an event from the loaded method back to where you initlize it.
Expand |
Embed | Plain Text
package { import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.events.IEventDispatcher; import flash.events.ProgressEvent; import flash.net.URLRequest; public class ImageLoader extends Sprite implements IEventDispatcher { public var newLoader : Loader; private var newRequest : URLRequest; private var assetsFolder : String; public var allowDomainUrl : String; private var percent: Number = 0; public function ImageLoader() { } public function load ( thisURL: String ):void{ // //Security.allowDomain( allowDomainUrl ); this.newLoader = new Loader(); //Security.allowDomain("*"); this.newRequest = new URLRequest( thisURL ); this.newLoader.load(this.newRequest); /* "Grasshopper - Remember to refer to the obj contentLoaderInfo which holds the data as it loads" */ this.newLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded); this.newLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, checkProgress); } public function checkProgress(e:ProgressEvent):void{ // percent = Math.ceil( e.bytesLoaded / e.bytesTotal ) * 100; } public function get progress ( ) : Number { return percent; } public function loaded(e:Event): void { //addChild( this.newLoader.content ); } } }
You need to login to post a comment.
