actionscript 3 - Set dimensions of a loaded image in Flash -


how set width , height of loaded image in flash? setting dimensions after requesting not work. width , height remain zero.

var poster:loader = new loader(); stage.addchild(poster); poster.load(new urlrequest('http://example.com/image.jpg')); poster.width = 320; poster.height = 240; trace(poster.width); // 0 trace(poster.height); // 0 

if wait short moment , set dimensions, work.

i tried listening event.init event , event.complete events before resizing suggested tutorials. neither of events triggered.

public function theclass() {     this.poster = new loader();     this.poster.contentloaderinfo.addeventlistener(event.init, this.imageloaded);     this.poster.contentloaderinfo.addeventlistener(event.complete, this.imageloaded);     stage.addchild(this.poster);     this.poster.load(new urlrequest('http://example.com/image.jpg')); }  private function imageloaded(event:event):void {     trace('image loaded');     this.poster.width = 320;     this.poster.height = 240; } 

in listener event.complete way it, there must wrong in loader code if event isn't being triggered. notice appear create local variable "poster" @ top of code posted don't declare inside of theclass() don't know if that's causing problem here.

also, customarily wait until after image has completed loading before add it, again don't know if that's causing problem here.

i mean, wrote following code minimal test , works fine:

public function main():void {   var loader:loader = new loader();   loader.contentloaderinfo.addeventlistener(event.complete, oncomplete);   loader.load(new urlrequest("image.png")); } private function oncomplete(e:event):void {   var img:bitmap = bitmap(e.target.content);   this.addchild(img);   img.width = 100;   img.height = 100; } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -