00:00
00:00
Newgrounds Background Image Theme

mariobros22 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Width of a nested MovieClip? -AS3-

429 Views | 2 Replies
New Topic Respond to this Topic

I know how to find the coordinates of a nested movie clip using this method:

var pt:Point = new Point(platform.hitBox.x, platform.hitBox.y);
pt = platform.hitBox.parent.localToGlobal(pt);

I also know how to get the x,y,width, and height of the nested clip by tracing:

this.hitBox.getBounds(stage);

Since the above snippet returns four values, one solution could be to tell me how to isolate the value I need and put it in a new variable. In the past, I've only ever dealt with functions that return a single value.

If not, I'm all ears to other solutions.

Response to Width of a nested MovieClip? -AS3- 2016-04-04 21:24:31


Hey, guys, i figured it out.

As it turns out, the getBounds() method returns a Rectangle value, so I just took the width of that rectangle.

var box = this.hitBox.getBounds(stage);	
trace(box.width);

Huzzah! These forums feel so dead nowadays..

Response to Width of a nested MovieClip? -AS3- 2016-04-04 21:47:02


At 4/4/16 09:24 PM, Barzona wrote: As it turns out, the getBounds() method returns a Rectangle value, so I just took the width of that rectangle.

Yeah, the getBounds() method wouldn't really work otherwise: it needs to take into account the relative x/y coordinates, as well as the dimensions of the bounds (such as the aforementioned width). It is really just a virtual rectangle surrounding the contents of the object.

It's worth reading the docs on the getBounds() function to ensure an understanding of what it's doing, but it's pretty straightforward: it returns the dimensions of the contents, including any stroke styles that may adjust them, and sets the x/y coordinates relative to the object passed to it (i.e. the x/y coordinates are set to the position of the calling object's position within the passed object, ignoring the passed object's position in its parent, should such a parent exist).

Having said that, from the looks of it, you should just be able to use the width() and height() methods.

At 4/4/16 09:13 PM, Barzona wrote: In the past, I've only ever dealt with functions that return a single value.

To be pedantic: It still is just returning a single value (i.e. a Rectangle object). The returned object just has four public members, which could be interpreted as "four values."