package
{
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
public class Main extends MovieClip
{
// state
private var iname:String = "image.gif";
private var w:int;
private var h:int;
private var loader:Loader;
// constructor
public function Main():void
{
loadImage( iname );
trace( w + " " + h );
}
// methods
private function loadImage( filename:String ):void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, completeHandler );
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, someHandler );
var request:URLRequest = new URLRequest( filename );
loader.load( request );
this.addChild( loader );
}
// event handlers
private function completeHandler( event:Event ):void
{
trace( "image loaded\n" + event.target.url );
trace( event.target );
}
private function someHandler( event:Event ):void
{
w = loader.contentLoaderInfo.width;
h = loader.contentLoaderInfo.height;
}
}
}
But when i ran i get 0 0 for width and height. How can i get the correct values ? Also if the picture is loaded correctly and after i attach it to a movieclip why i cannot take the width and height from movieclip object?