Solved

Scaling movieclips

Posted on 2006-11-17
4
1,243 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
ID: 17967562
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
ID: 17968253
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
ID: 17969943
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
ID: 17978117
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

791 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