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;
}
}
}
但是,當我跑我得到0 0的寬度和高度。我怎樣才能得到正確的值? 此外,如果圖片加載正確後,我附加到一個movieclip爲什麼我不能從movieclip對象的寬度和高度?如何從裝載機對象獲取寬度和高度
請花幾秒鐘的時間清理任何評論的代碼,然後再發布到這裏,這對我們來說只是更多的閱讀,它並沒有真正做任何事情。 – grapefrukt 2010-02-22 16:25:19