开发者

Flash AS3: How do you calculate the width of an image loaded into a movieclip?

I am loading an image into a movie clip via AS3, and what I want to do is center the image inside the movieclip. The problem is that I can't seem to grab the width value of the image being loaded. Below is what I'm doing:

imageLoader = new Loader();
imageLoader.load(new URLRequest(event.target.name));
screenBox.screenHolder.addChild(imageLoader);
trace(this.imageLoader.width);

When I trace the width, it always comes back at zero(0) even though there is an image inside the image开发者_如何学GoLoader. What is it I need to do to find the actual width so I can center the image?


ActionScript Retrieving Width/Height Of Loader Image

you have to load it first

imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedImage);
imageLoader.load(new URLRequest(event.target.name));
screenBox.screenHolder.addChild(imageLoader);

function loadedImage(event:Event):void {
   trace(event.target.content.width);
}


Have you tried doing validateNow() after adding the imageLoader and before you try to get its width?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜