在 AS3 (Action Script 3.0) 中查找(加载)图像大小 [英] Finding (loaded) image size in AS3 (Action Script 3.0)

查看:13
本文介绍了在 AS3 (Action Script 3.0) 中查找(加载)图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用以下函数来加载图像,但是我无法找到一种方法来找到加载图像的宽度,我打算在使用相同函数放置下一个图像之前使用它.

Im currently using the following function to load an image, however i could not figure out a way to find the width of the loaded image, which i intend to use before placing the next image using the same function.

请注意,q 是一个变量(一个数字),用于加载不同的图像.

Note that q is a a variable (a number) which is used to load differant images.

=X 我需要帮助获取加载的图像宽度...

=X i need help obtainning the loaded image width...

function LoadImage(q)
{
    var imageLoader:Loader = new Loader();
    var image:URLRequest = new URLRequest("GalleryImages/Album1/"+q+".jpg");
    imageLoader.load(image);
    addChild (imageLoader);
    imageLoader.x = 0 + CurrentXLength;
    imageLoader.y = 0;
    imageLoader.name = "image"+q;
    trace(imageLoader.x)
}

推荐答案

在实际加载之前,您无法知道位图的宽度:

You can't know the width of the bitmap until it's actually loaded:

function LoadImage(q)
{
    var imageLoader:Loader = new Loader();
    var image:URLRequest = new URLRequest("GalleryImages/Album1/"+q+".jpg");
    imageLoader.contentLoader.addEventListener(Event.COMPLETE, ImageLoaded);
    imageLoader.load(image);
    addChild (imageLoader);
    ...


private function ImageLoaded(e:Event):void
{
    var imageLoader:Loader = Loader(e.target.loader);
    var bm:Bitmap = Bitmap(imageLoader.content);
    var CurrentXLength = bm.width;
    ....

或者这个链接 可能有帮助吗?自己没试过...

Alternativly this link might be helpful? Haven't tried it myself ...

这篇关于在 AS3 (Action Script 3.0) 中查找(加载)图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆