Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 在AS3中更改宽度和高度后,MovieClip消失_Actionscript 3_Flash_Flash Cs5_Flashdevelop - Fatal编程技术网

Actionscript 3 在AS3中更改宽度和高度后,MovieClip消失

Actionscript 3 在AS3中更改宽度和高度后,MovieClip消失,actionscript-3,flash,flash-cs5,flashdevelop,Actionscript 3,Flash,Flash Cs5,Flashdevelop,我正在尝试从as3中的url加载图像,如下所示: 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(m

我正在尝试从as3中的url加载图像,如下所示:

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);
上面的代码工作得很好,但是由于我的愿望图像与原始图像的大小不同,因此在这里更改其大小是必要的。因此,在使用上述代码中注释的行之后,mcImage将消失


我尝试使用mcImage.scaleX=myImageLoader.width/50,但由于myImageLoader在开始时没有加载,我们无法获得myImageLoader的宽度为空。

设置大小时经常出错,无法设置空显示对象(宽度和高度为零的对象)的大小。要设置显示对象的大小,您首先需要在其
图形上绘制一些东西(例如1*1 px矩形),但您应该了解,在绘制之后,您只需将显示对象相对于其原始大小进行缩放,例如,如果您绘制1*1 px矩形并设置为=height=50,则其scaleX和scaleY将为50,所以,如果我们说加载程序,那么加载的图像将是巨大的:)这都是关于flash中的大小

你的任务是什么:有一个共同的规则-不调整加载程序的大小,调整加载的图像大小。正如我上面所说,调整加载程序的大小只会缩放图像,而不会设置图像的大小。添加完整的处理程序并根据需要调整loader.content的大小

例如:

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;
}

在玩MC之前,您需要在加载程序上获取loadComplete事件

var myImageLoader:Loader = new Loader();
private var mcImage: MovieClip = new MovieClip();
var myImageLocation:URLRequest = new URLRequest("http://example.com/xyz.jpg");

myImageLoader.addEventListener(Event.COMPLETE, completeHandler);
myImageLoader.load(myImageLocation);

function completeHandler(e:Event){
    mcImage.x = 100;
    mcImage.y = 100;
    mcImage.width = 50;
    mcImage.height = 50;
    addChild(mcImage);
    mcImage.addChild(myImageLoader);
}
试试这个:

var myImageLoader:Loader = new Loader();
//hide until loaded
myImageLoader.visible = false;
//listen for load completed
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
//...rest of your code (without setting width/height)
然后添加此选项以调整大小并使加载时可见:

function completeHandler(event:Event):void
{
    myImageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler);
    myImageLoader.content.width = 50;
    myImageLoader.content.height = 50;
    myImageLoader.visible = true;
}

Try:myImageLoader.width=50;myImageLoader.height=50;我以前也试过,同样的问题。您需要等待图像加载,然后管理其大小。我会在Flash Square上发布一个答案但您应该将侦听器添加到contentLoaderInfo