简体   繁体   English

as3获取调整大小的movieclip的宽度

[英]as3 get width of resized movieclip

I have a movie clip that I scaled by hand in the timeline. 我有一个影片剪辑,我在时间轴上手动缩放。

I am now trying to get the WIDTH and HEIGHT with action script so I can load another movieClip into it and make it the same size. 我现在正试图通过动作脚本获得WIDTH和HEIGHT,因此我可以将另一个movieClip加载到其中并使其大小相同。

However when I do the following code I can't position it correctly because the scale is WIDTH and HEIGHT displays the original size and not showing the scaled size cordinates. 但是,当我执行以下代码时,我无法正确定位它,因为比例为WIDTH,HEIGHT显示原始大小而不显示缩放大小的坐标。 So when I place the new clip inside of it the I can't make it be the same WIDTH and HEIGHT as the rescaled clip; 因此,当我将新剪辑放入其中时,我无法使其与重新缩放的剪辑具有相同的宽度和高度;

ScaledMC.addChild(myMC);
myMC.x = - ScaledMC.width /2; //Because the MC registration is in the center

A work around could be some code to detect the x and y positions of the BOUNDARIES of the clip and where they are located on the stage. 解决方法可以是一些代码来检测剪辑的BOUNDARIES的x和y位置以及它们在舞台上的位置。

Thanks for your time. 谢谢你的时间。

UPDATE: 4-25-12 更新:4-25-12

I am posting full code of what I am trying to do and including FLA. 我发布了我正在尝试做的完整代码,包括FLA。 When you click on the girl I need her to load into another movie clip. 当你点击女孩我需要她加载到另一个电影剪辑。 However the movie clip is scaled so when she gets loaded her position suddenly changes. 然而,影片剪辑是缩放的,所以当她被加载时,她的位置突然改变。 I need it to look like she hasn't moved and stays in the same place. 我需要它看起来像她没有移动并停留在同一个地方。

import flash.geom.Rectangle;

var Girlx = Girl.x;
var Girly = Girl.y;

var b:Rectangle;
b = Room.ChalkBoard.getBounds(this);


trace(b);


Room.ChalkBoard.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

function fl_ClickToDrag(event:MouseEvent):void
{
    Room.ChalkBoard.startDrag();
}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

function fl_ReleaseToDrop(event:MouseEvent):void
{
    Room.ChalkBoard.stopDrag();
    b = Room.ChalkBoard.getBounds(this);
}



Girl.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
    //Room.ChalkBoard.scaleX = 1;
   // Room.ChalkBoard.scaleY = 1;
    Room.ChalkBoard.addChild(Girl);


    // I NEED TO KNOW HOW TO SCALE GIRL BACK TO SAME SIZE
    // EXAMPLE:

Girl.scaleY = 1 + Room.ChalkBoard.scaleY;

Girl.scaleX = 1 + Room.ChalkBoard.scaleX;
Girl.x = Girlx - b.x; /// This formula works if Room is at scaleX is 1;
Girl.y = Girly - b.y;  /// This formula works if Room is at scaleY is 1;


}

HERE IS THE FLA: http://www.EdVizenor.com/Girl.fla 这里是FLA: http ://www.EdVizenor.com/Girl.fla

If your problem is that you scale the movieclip and want to use the original dimensions (I think this is what you are saying) then you could try something like the following: 如果您的问题是您缩放动画片段并想要使用原始尺寸(我认为这就是您所说的),那么您可以尝试以下内容:

ScaledMC.addChild(myMC); 
myMC.x = - (ScaledMC.width/ScaledMC.scaleX) /2; 

Notice that I added in a factor for scaling of the movieclip object itself 请注意,我添加了一个缩放movieclip对象本身的因子

You can access the transformation Matrix that represents the object you've scaled with the IDE to work out how much you've scaled it. 您可以访问转换Matrix ,该Matrix表示您使用IDE缩放的对象,以计算出您缩放的对象数量。 The key properties of Matrix that you want to look at are a for x-scale and d for y-scale. 的关键性能Matrix ,你想看看是a用于X规模和d y的规模。

Demo: 演示:

var matrix:Matrix = ScaledMC.transform.matrix;
trace(matrix.a, matrix.d);

You can then use the values to scaling your additional MovieClips, or whatever you need to do. 然后,您可以使用这些值来扩展您的其他MovieClip,或者您需要做的任何事情。

Bonus: Have a function: 额外奖励:有一个功能:

function getScale(target:DisplayObject):Object
{
    var mtx:Matrix = target.transform.matrix;

    return {
        scaleX: mtx.a,
        scaleY: mtx.d
    }
}


// Get scaleX of ScaledMC.
trace(getScale(ScaledMC).scaleX);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM