as3得到缩放/调整大小的宽度和高度 - movieClip / mc?

时间:2012-05-22 03:02:31

标签: actionscript-3 flash height width scale

我经常缩放一个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

...

如何获得新的宽度和高度?

2 个答案:

答案 0 :(得分:1)

您可能遇到阶段缩放问题。

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

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

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

您提供的示例未解决问题。它按预期工作。

size scale

如果您正在进行基于帧的动画,也可以使用跟踪语句的时间。也许你正在查看一个大小不正确的工件,而不是与你期望的生命周期一致。

答案 1 :(得分:-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! :)