1

我经常缩放一个movieClip,需要根据它的大小将它放在屏幕上的某些地方。

缩放后,如何获得影片剪辑的宽度和高度?

trace(my_mc.width); /// would equal 333

/// This code makes my movie clip fit in the correct proportions. 
my_mc.height = stage.stageHeight;
my_mc.scaleX = my_mc.scaleY;

/// Its been resized!
trace(my_mc.width); /// STILL equals 333

..

任何想法如何获得新的宽度和高度?

4

2 回答 2

1

您可能遇到舞台缩放问题。

如果您依赖于舞台大小,请设置:

import flash.display.StageAlign;
import flash.display.StageScaleMode;

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

您提供的示例没有封装问题。它按预期工作。

规模

如果您正在制作基于帧的动画,也可能是跟踪语句的时间安排。也许您正在查看大小的工件,而不是您期望的生命周期。

于 2012-05-22T03:35:22.340 回答
-1

感谢您的所有努力。我找到了答案!:)


import flash.display.MovieClip;

/// My stage is 500 by 500.
/// My Image or movieClip is 446 by 688.
/// I am calling it my_mc.
trace(my_mc.width + " by " + my_mc.height); /// OUTPUT: 446 by 688

// I want the height to match the height of my stage but keep the same 
// proportions. So I use the code below. WORKS GREAT!
my_mc.height = stage.stageHeight;
my_mc.scaleX = my_mc.scaleY;

// But if I want to trace the width and the height it will still be the same.
trace(my_mc.width + " by " + my_mc.height); /// OUTPUT: 446 by 688.


///So I make a NEW movieClip below after I scaled it.
var NewMC:MovieClip = my_mc as MovieClip; 

/// NOW WHEN I TRACE IT... :)
trace(NewMC.width + " by " + NewMC.height); /// 324.1 by 500

// YES!!! I can't believe I figured this out on my own! Woo hoo! :)
于 2012-05-22T04:05:12.383 回答