Groups | Blog | Home
all groups > flash actionscript > june 2004 >

flash actionscript : setting button _width and _height



colloquialism
6/13/2004 10:43:07 PM
Hello,

I'm pretty new to Flash so I'm still learning all its capabilities, but I come
from a software development background. I'm trying to resize and reposition a
button based on the attributes of a movie clip using the following function:

function resizeHitArea(movie, button){
mBounds = movie.getBounds(_root);
button._height = (mBounds.yMax - mBounds.yMin);
button._width = (mBounds.xMax - mBounds.xMin);
button._x = mBounds.xMin;
button._y = mBounds.yMin;
}

Now _x and _y are being set properly and the button is being repositioned.
However, if I trace the values of _height and _width they are both being reset
to 0.

The same is true if I harcode the values, ie button._width = 100. Immediately
after setting it the value changes to 0.

Any info is appreciated.
MechaFlasher
6/14/2004 11:03:38 PM
Don't know why button._width and _height would reset to 0 like that if you set
it to 100. There's must be something else funky going on somewhere, I'd have
to know more. Not knowing anything else, one thing I see right away though is
that if both the movieclip and the button are at the same level (not nested
within each other or in different clips) then you don't need to use .getBounds.
Just set properties this way: button._x = movie._x. If they are nested then
you can set the dimensions the same way still, and use getBounds for the
positioning but MovieClip.localToGlobal or GlobalToLocal might be better for
your use.
AddThis Social Bookmark Button