Solved

Scaling movieclips

Posted on 2006-11-17
4
1,235 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Embedding Flash App/Movie on Website 3 490
Streaming to Flash Media Server with ffmpeg, crashes on start 3 234
Action Script commands 4 305
Flash Player Action Script Error 1090 5 197
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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 live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to record live broadcast.

863 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

23 Experts available now in Live!

Get 1:1 Help Now