如何调整动态加载图像到Flash(AS3) [英] How to resize dynamically loaded image into flash (as3)

查看:285
本文介绍了如何调整动态加载图像到Flash(AS3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在努力寻找合适的AS3 code来调整图像一旦动态调用到舞台上,并放置在一个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.

我需要做的是在装载缩小到同一高度的舞台,同时保持宽度比例(OH和中心的话)。 我已经试过各种codeS,但无法找到任何工作,因为所有我设法做的是调整包含图像而不是图像本身的MC。 任何指导,以正确的code会大大AP preciated。

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.

我guessng这很简单,只要像

I am guessng it is as simple as something like

 "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屋!

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