在AS3中发现(加载)图像尺寸(动作脚本3.0) [英] Finding (loaded) image size in AS3 (Action Script 3.0)
问题描述
即时通讯目前使用下面的函数来加载图像,但我无法想出一个办法,找到加载图像的宽度,我打算使用相同的功能将在接下来的图像前使用。
请注意q是氨基酸变量(一个数字),其用于装载歧图像。
= X我需要帮助obtainning加载的图像宽度...
函数的LoadImage(Q)
{
VAR ImageLoader的:装载机=新的Loader();
VAR图像:的URLRequest =新的URLRequest(GalleryImages / Album1 /+ Q +。JPG);
imageLoader.load(图像);
的addChild(ImageLoader的);
imageLoader.x = 0 + CurrentXLength;
imageLoader.y = 0;
imageLoader.name =形象+ Q;
跟踪(imageLoader.x)
}
您无法知道位图的宽度,直到它的实际加载:
函数的LoadImage(Q)
{
VAR ImageLoader的:装载机=新的Loader();
VAR图像:的URLRequest =新的URLRequest(GalleryImages / Album1 /+ Q +。JPG);
imageLoader.contentLoader.addEventListener(引发Event.COMPLETE,ImageLoaded);
imageLoader.load(图像);
的addChild(ImageLoader的);
...
私有函数ImageLoaded(五:事件):无效
{
VAR ImageLoader的:装载机=装载机(e.target.loader);
变种BM:位图=位图(imageLoader.content);
VAR CurrentXLength = bm.width;
....
Alternativly <一href="http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/">this链接可能会有所帮助?还没有尝试过自己...
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.
Note that q is a a variable (a number) which is used to load differant images.
=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中发现(加载)图像尺寸(动作脚本3.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!