movieclip奇怪地重新缩放

时间:2011-08-31 19:43:14

标签: flash actionscript-3

var pic0ldr:Loader = new Loader();
var thumb0Req:URLRequest = new URLRequest("0.jpg");
pic0ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, function(evt:Event){onComplete(evt, "stgW","stgH")});
pic0ldr.load(thumb0Req);

function onComplete(event:Event,stgW,stgH):void {
this[stgW] = event.target.content.width;
this[stgH] = event.target.content.height;
placeem("stgW","stgH");
}

function placeem(stgW,stgH):void {

leftmask_mc.height = this["stgH"];
leftmask_mc.width = this["stgW"];
pic0ldr.y = -this["stgH"];
pic0ldr.x = -this["stgW"];

trace(leftmask_mc.width,leftmask_mc.height,pic0ldr.height,pic0ldr.width);//500 707 707 500


leftmask_mc.addChild(pic0ldr);  //strange resize

leftmask_mc.height = this["stgH"];//
leftmask_mc.width = this["stgW"]; // normal again, without 569.25 845.55 707 500

trace(leftmask_mc.width,leftmask_mc.height,pic0ldr.height,pic0ldr.width);
}

您可能想知道为什么我需要宽度和高度数据来调整我的movieclip的大小,但是我加载了很多图片而且我必须获得最大高度和宽度

2 个答案:

答案 0 :(得分:0)

有点难以确定您的问题是什么,因为您实际上并没有问过,但我想问题是这样的:

如果将MovieClip的宽度和高度(例如leftmask_mc)设置为比原来的其他比例,则会失真。您添加到该MovieClip的任何子项也将以相同的方式失真,因为它成为该MovieClip的一部分。

此外,如果要将leftmask_mc用作蒙版,您可能不希望将加载的图像添加为leftmask_mc的子图像。如果希望leftmask_mc屏蔽图像,则应将图像(或包含图像的DisplayObject)的.mask属性设置为leftmask_mc。

答案 1 :(得分:0)

真的不知道你在问题中提到了什么 但我会告诉你,你的代码示例是可怕的,你到处都是函数,甚至使用无名函数。

leftmask_mc.height = this["stgH"];
leftmask_mc.width = this["stgW"];
pic0ldr.y = -this["stgH"];
pic0ldr.x = -this["stgW"];

trace(leftmask_mc.width,leftmask_mc.height,pic0ldr.height,pic0ldr.width);//500 707 707 500

// this is your problem when you pic0ldr, pic0ldr is is set to a NEGATIVE X and Y Which will cause leftmask to resize that amount
leftmask_mc.addChild(pic0ldr);  //strange resize

同样,您需要重新编写问题并重新编写代码,以便我们能够理解它是否清晰