1
votes

I am scaling a movieClip often and need to place it on the screen in certain places according to its size.

Once scaled, how can I get the WIDTH and HEIGHT of a movie clip?

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

..

Any ideas how to get new width and height?

2
Pasting this code in Flash shows width change - is this your actual code?Jason Sturges
No its just an example. But the width does change with this code. Both height and width does. I didn't do the math. That is a great code bit from some smart Stack Overflower.Papa De Beau
Thanks `Papa` I've been looking for stage.stageWidth and stage.stageHeight since I started Flash dev. upvotedBitterblue

2 Answers

1
votes

You're probably experiencing stage scaling issues.

If you're dependent on stage size, set:

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

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

Your provided example doesn't encapsulate the problem. It works as expected.

size scale

Also possible is timing of your trace statements, if you're doing frame-based animation. Perhaps you're viewing an artifact of size instead of in line with the lifecycle you expect.

-1
votes

Thanks for all your effort. I found the answer! :)


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! :)