Solved

Scaling movieclips

Posted on 2006-11-17
4
1,254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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 goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
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.

696 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