Solved

Scaling movieclips

Posted on 2006-11-17
4
1,231 Views
Last Modified: 2007-12-19
Hello

I have a movieclip that contains a button.

When I scale the movie clip, its width/height change accordingly, but when I trace the height/width/location of the button they remain the same:

example:

trace(this._parent.map_mc._width);
trace(this._parent.map_mc._height);
trace(this._parent.map_mc._x);
trace(this._parent.map_mc._y);
trace(this._parent.map_mc.obj._x);
trace(this._parent.map_mc.obj._y);
trace("===========================");

this._parent.map_mc._xscale = 245;
this._parent.map_mc._yscale = 245;

trace(this._parent.map_mc._width);
trace(this._parent.map_mc._height);
trace(this._parent.map_mc._x);
trace(this._parent.map_mc._y);
trace(obj._x);
trace(obj._y);

this produces:

697.85
401.05
1.5
-6.85
145
171.25
===========================
3783.45
2174.35
1.5
-6.85
145
171.25

-------------------------------------------------------------

Note: obj is a button inside map_mc. when the flash is rendered, the button looks bigger and in the correct place.

My question is, how do I get the new values of the button after the scaling has taken place?

Any help would be greatly appreciated. Thanks
0
Comment
Question by:bLUE
4 Comments
 
LVL 37

Expert Comment

by:CyanBlue
Comment Utility
I think you've got to do some math in relationship with the value of _xscale and _yscale to get the correct values...  ;)

CyanBlue
0
 
LVL 7

Expert Comment

by:muxxter
Comment Utility
Hi bLUE.

The reason the _x and _y values aren't changing is because they are the position of the object's reference point. By default, it is the top, left corner of the object. So, even though the center of the object seems to move when you change the scale, it's reference point doesn't.

"What about map_mc.obj?" you ask. Well, since you're changing the scale of map_mc, the objects inside it don't change their position relative to it. And when you grab map_mc.obj._x, you get the object's position within map_mc, not within the scene.

Let me know if any of that doesn't make sense. :-)

Gav
0
 
LVL 5

Accepted Solution

by:
blockage1 earned 125 total points
Comment Utility
There are a couple of ways you can find the new location without doing the math your self...

1a. localToGlobal will convert any point in one clip to the _root's coord space to the _root's coord space.
var point:Object = {
             x:map_mc.obj._x,
             y:map_mc.obj._y
};
map_mc.localToGlobal( point );
trace( [ point.x , point.y ] );

1b. You can then convert this to any other coordinate space
another_mc.globalToLocal( point );
trace( [ point.x , point.y ] );


2. getBounds will give you the boundary edges of the button in any coord space you specify (in this example I've used the _root's coord space).
var bounds:Object  = map_mc.obj.getBounds( _root );
var left = bounds.xMin;
var right = bounds.yMin;
var top = bounds.xMax;
var bottom = bounds.yMin;

Note: getBounds works on the actual edge of the graphics within a movieclip regardless of where its reg point is.
0
 
LVL 1

Author Comment

by:bLUE
Comment Utility
Thanks for the help guys. I got it working:

var strButton = "button_178";
var objButton = eval(strButton);

this._parent.map_mc._xscale = 245;
this._parent.map_mc._yscale = 245;

var point:Object = {
             x:this._parent.map_mc.objButton._x,
             y:this._parent.map_mc.objButton._y
};
this._parent.map_mc.localToGlobal( point );

//set the button to (0,0)
this._parent.map_mc._x = (-1)*point.x;
this._parent.map_mc._y = (-1)*point.y;

//center the button to the canvas
this._parent.map_mc._x = this._parent.map_mc._x + 250;
this._parent.map_mc._y = this._parent.map_mc._y + 200;

//change the colour of the button
var colorful = new Color(this.objButton);
      colorful.setRGB(0x003366);

It seems to center the button to the screen. Only thing that doesnt work.. is changing the colour of the button !
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now