?
Solved

Scaling movieclips

Posted on 2006-11-17
4
Medium Priority
?
1,260 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 500 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 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