2011-08-31 56 views
0
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); 
} 

你也许会奇怪,为什么我需要的宽度和高度数据来调整我的影片剪辑,但我加载很多照片,我必须得到最大的高度和宽度影片剪辑再缩放奇怪

回答

0

有点很难确定什么你的问题是,因为你实际上并没有问一个,但我猜问题是这样的:

如果你设置一个MovieClip的宽度和高度,比如你的leftmask_mc,到其它比例,它会是原来的扭曲。您添加到该MovieClip的任何孩子也将以相同的方式变形,因为它成为该MovieClip的一部分。

此外,如果leftmask_mc旨在用作掩码,则可能不希望将已加载的图像作为leftmask_mc的子项添加。如果您想让leftmask_mc遮罩图像,则应该将图像的.mask属性(或包含该图像的DisplayObject)设置为leftmask_mc。

+0

我的问题是在代码注释,我不希望用它作为一张面具。我所做的是将mc大小设置为图片的大小,并使用addChild将其加载到该图片上,但是在完成该操作后,mc的大小会变大,尽管我已经定义了它。重新定义后它又恢复正常。至于比例的宽度/高度,我不认为这是我给它的另一个宽度不是图片的情况下,它静止添加相同的像素的高度和一些到宽度 – TasostheGreat

+0

确定。仍然有点难以确定你正在尝试做什么,我认为什么是不工作,但我会再试一次,如果你想要的只是使用leftmask_mc作为加载图像的持有者,你不要不需要将高度和宽度设置为与图像相同。将图像添加为小孩时,leftmask_mc将自动采用图像的大小(其内容的大小)。 –

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 

同样需要改写你的问题和返工您的代码,以便它是清晰可辨的地步,我们可以把它理解