如何将动态加载的图像调整为 Flash (as3) [英] How to resize dynamically loaded image into flash (as3)
问题描述
我正在努力寻找正确的 as3 代码来在动态调用舞台并放置在 MC 中后调整图像大小.我正在加载:
Am struggling to find the right as3 code to resize an image once it is dynamically called into the stage and placed in a MC. I am loading using:
var myLoader :Loader = new Loader();
mc.addChild(myLoader);
var url :URLRequest = new URLRequest("myimage.jpg");
myLoader .load(url );
舞台最终会全屏打开(工作正常),所以我需要将图像保持在比舞台大得多的原始尺寸.
The stage will eventually open up into fullscreen (works ok) so I need to keep the image in its original size which is much bigger than the stage.
我需要做的是在加载时将其缩小到与舞台相同的高度,同时保持宽度成比例(哦并居中).我已经尝试了各种代码,但找不到任何可以工作的方法,因为我所做的只是调整包含图像的 MC 而不是图像本身的大小.任何有关正确代码的指导将不胜感激.
What I need to do is shrink it on loading to the same height as the stage whilst keeping the width in proportion (oh and center it). I have tried all sorts of codes but cant find anything to work as all I have managed to do is resize the MC containing the image but NOT the image itself. Any guidance as to the correct code would be greatly appreciated.
我猜它就像这样简单
"myimage".x=600;
但是如果是这样,写图像名称的正确方法是什么,正如我所写的那样似乎是错误的.非常感谢
but if so what is the correct way to write the image name, as I have written it seems erroneous. Many thanks
埃德
推荐答案
我试着回答你的问题
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
var myLoader:Loader = new Loader();
var image:Bitmap;
var url :URLRequest = new URLRequest("im1.jpg");
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
myLoader.load(url);
function onImageLoaded(e:Event):void {
image = new Bitmap(e.target.content.bitmapData);
var mw:Number = stage.stageWidth;
var mh:Number = stage.stageHeight;
/* if you set width and height image same with the stage use this */
image.width = mw;
image.height = mh;
mc.addChild(image);
}
这篇关于如何将动态加载的图像调整为 Flash (as3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!