改变AS3的宽度和高度后,影片剪辑消失 [英] MovieClip disappear after changing width and height in AS3

查看:212
本文介绍了改变AS3的宽度和高度后,影片剪辑消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从AS3的URL加载图像,如下所示:

I am trying to load an image from an url in as3, as follows:

var myImageLoader:Loader = new Loader();
private var mcImage: MovieClip = new MovieClip();
var myImageLocation:URLRequest = new URLRequest("http://example.com/xyz.jpg");
myImageLoader.load(myImageLocation);
mcImage.addChild(myImageLoader);
mcImage.x = 100;
mcImage.y = 100;
//mcImage.width = 50;
//mcImage.height = 50;
addChild(mcImage);

在code以上工作正常,但因为我的愿望图像具有比较原始图像不同的大小,改变它的大小是有必要在这里。所以在使用的线路,这些评论在code以上时,mcImage消失。

The code above works fine, but since my desire image has a different size comparing to the original image, changing its size is necessary here. So after using the lines, which are commented in the code above, the mcImage disappear.

我试图使用 mcImage.scaleX = myImageLoader.width / 50 ,但由于myImageLoader没有在一开始加载,我们不能得到myImageLoader的宽度为null。

I tried to use mcImage.scaleX =myImageLoader.width/50 , but since myImageLoader is not loaded at the beginning, we cannot get the width of myImageLoader which is null.

推荐答案

这是通常误差大小的设置,你可以不设置大小(对象的宽度和高度均为零)。要设置您需要先画了东西的显示对象的尺寸是图形(例如1 * 1像素的矩形),但你应该明白,以后它,你将只是扩展您显示对象相对于它的原始尺寸,例如,如果你画1 * 1像素的矩形,并设置=身高= 50,将scaleX和scaleY因为这将是50,所以你加载的图像,如果我们说的装载机将是巨大的大小:)这是所有关于Flash大小。

It's the often error with setting sizes, you can't set size of empty display object (object that width and height are zero). To set size of display object you need first to draw something on it's graphics (for example 1*1 px rectangle), but you should understand that after it you will just scale your display object relatively to it's original size, for example if you draw 1*1 px rectangle and set with=height=50, scaleX and scaleY for it will be 50, so your loaded image if we say about loader will be giant size :) It's all about sizing in flash.

那你的任务:有一个共同的规则 - 的不要调整装载机,调整加载的图像的。正如我上面所说的装载机的大小调整的仅是你的形象,而不是将其设置大小。添加完整的处理程序,并调整loader.content你想要的。

What about your task: there is one common rule - don't resize loader, resize loaded image. As I said above resizing of loader will only scale your image rather than set it sizes. Add complete handler and resize loader.content as you want.

例如:

public function astest()
{
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplte);
    addChild(loader);

    loader.load(new URLRequest("https://www.google.ru/images/srpr/logo3w.png"));
}

protected function onComplte(event:Event):void
{
    EventDispatcher(event.target).removeEventListener(event.type, arguments.callee);
    var image:DisplayObject = (event.target as LoaderInfo).content;

    image.width = 50;
    image.height = 50;
}

这篇关于改变AS3的宽度和高度后,影片剪辑消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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