Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-21-2007, 09:59 PM   #1
Senior Member
Join Date: Nov 2002
Location: CA
Posts: 454
Default Get _height of clip with TextField?

I have a movieclip, 400x400, which several child clips down contains a ScrollPane that in turn contains a clip that's about 6000 pixels tall.

The problem is that when I call _height on the 400x400 clip, it's returning 6000 (the _height of it's child.child.child.) instead of 400.

Is this normal behaviour or am I doing something wrong? How can I get an accurate _height from this clip, regardless of what it contains?

EDIT (To help others, since the solution is now below)

How do you get the rect of a masked movieclip?
How do you get the height width of a masked movieclip?

Last edited by Arodicus; 06-21-2007 at 11:29 PM. Reason: To help others, since the solution is now below
Arodicus is offline   Reply With Quote
Old 06-21-2007, 10:53 PM   #2
it's all about patience
inhan's Avatar
Join Date: Jun 2005
Location: istanbul
Posts: 6,696

It is a normal behavior because each mc is extended by its children (the nested mc's within).
Ali Inhan
Turkish graphic and web designer
an Apple fan
inhan is offline   Reply With Quote
Old 06-21-2007, 11:26 PM   #3
Senior Member
Join Date: Nov 2002
Location: CA
Posts: 454
Cool Near-solution!!!

Well, it's LAME behavior: there should be a "get visible rect" option, and there isn't...

So I wrote one!

import flash.display.*;
import flash.geom.Matrix;
import flash.geom.Rectangle;

// getVisibleRect(myClip:MovieClip):Rectangle
// Returns the rect of just the visible portion of the given movieclip, factoring out any hidden, invisible (alpha 0)
// or masked regions; this will include the additional padding created by adding filters or wide linestyles
// to the clip or its visible children.
function getVisibleRect(myClip, myScale) {

	// by default, assume we are using a normal scale.
	if (!myScale) {
		myScale = 1;
	// Get x/y Min/Max rect of clip, including all masked elements:       
	var clipRect = myClip.getRect();

	// create a blank Bitmap of the largest possible size. 
	var myBitmapData:BitmapData = new BitmapData(2880, 2880);

	// adjust Matrix so it captures entire clip image, regardless of if it's been drawn in negative space,
	// by moving the entire clip into the fourth quadrant (origin 0,0), and then scale it if necessary:
	var myMatrix:Matrix = new Matrix(1, 0, 0, 1, -clipRect.xMin, -clipRect.yMin);

	// draw a bitmap copy of myClip onto the bitmap:

	var colorBoundsRect:Rectangle = myBitmapData.getColorBoundsRect(0xFFFFFFFF, 0xFFFFFFFF, false);

	if (((colorBoundsRect.x+colorBoundsRect.width) == 2880) || ((colorBoundsRect.y+colorBoundsRect.height) == 2880)) {
		// We've exceeded bounds of bitmap; scale back and try again.
		var scaleBackFactor = 2;
		colorBoundsRect = getVisibleRect(myClip, myScale/scaleBackFactor);
		colorBoundsRect.x *= scaleBackFactor;
		colorBoundsRect.y *= scaleBackFactor;
		colorBoundsRect.width *= scaleBackFactor;
		colorBoundsRect.height *= scaleBackFactor;
	// Resulting rect now contains x/y: the offset of the visible clip within it's overall mask area,          
	// and width/height: the physical dimensions of the visible clip. Note that both values include any padding caused
	// by line thickness or applied filters of the clip or any clip it contains.

	// Knowing mcClips relation to the mask of its child is pretty useless, so let's adjust XY one final time so that they 
	// reflect the visible portion of mcClip in relation to it's own origin:
	colorBoundsRect.x += clipRect.xMin;
	colorBoundsRect.y += clipRect.yMin;
	return colorBoundsRect;

// create a clip that contains a really big clip which is masked:
mcClip = this.createEmptyMovieClip("myClip", this.getNextHighestDepth());

// draw a box in "mcClip", starting in quad1, that extends into all 4 quadrants.
mcClip._x = 133;
mcClip._y = 133;
traceSize("Initial values of mcClip:");
//Prop:   _x:133 _y:133 _w:201 _h:151
//Rect: xMin:-50 yMin:-75 xMax:150 yMax:75
//Mask: (x=-50, y=-75, w=201, h=151)

// Scale back McClip. Note that while _height and _Width adjust by 50%,
// the visibleRect remains the same, since it is calculated as it pertains
// to its own space.
mcClip._xscale = 50;
mcClip._yscale = 50;
traceSize("Scaled mcClip and its subclips to 50%");
//Prop:   _x:133 _y:133 _w:100.5 _h:75.5
//Rect: xMin:-50 yMin:-75 xMax:150 yMax:75
//Mask: (x=-50, y=-75, w=201, h=151)

// create a big-ass mutha of a subclip. Note how it makes mcClip waaaay bigger:
mcGoliath = mcClip.createEmptyMovieClip("goliath", mcClip.getNextHighestDepth());
traceSize("Added a really big subclip to mcClip:");
//Prop:   _x:133 _y:133 _w:7502.3 _h:7502.3
//Rect: xMin:-1000 yMin:-1000 xMax:14000 yMax:14000
//Mask: (x=-15000, y=-15000, w=15008, h=15008)

// Finally, create a mask subclip and mask its sibling: Note that the size of 
// mcClip stays huge, even though its goliath subclip is no longer fully visible:
mcMask = mcClip.createEmptyMovieClip("myMask", mcClip.getNextHighestDepth());
traceSize("Masked the huge subclip to fit inside mcClip again.");
//Prop:   _x:133 _y:133 _w:7502.3 _h:7502.3
//Rect: xMin:-1000 yMin:-1000 xMax:14000 yMax:14000
//Mask: (x=-50, y=-75, w=201, h=151)

function drawRect(target_mc:MovieClip, x:Number, y:Number, width:Number, height:Number, color:Number) {
	var depth:Number = target_mc.getNextHighestDepth();

function traceSize(strComments) {
	trace("Prop:   _x:"+mcClip._x+" _y:"+mcClip._y+" _w:"+mcClip._width+" _h:"+mcClip._height);
	trace("Rect: xMin:"+mcClip.getRect().xMin+" yMin:"+mcClip.getRect().yMin+" xMax:"+mcClip.getRect().xMax+" yMax:"+mcClip.getRect().yMax);
	trace("Mask: "+getVisibleRect(mcClip));
Basically what this does is capture a bitmap of the movieclip in question, and then looks for the rectangle that isn't composed of only transparent pixels. The result are the actual VISIBLE dimensions of the clip, ignoring all the masked areas. It's a bit slow, and a brief memory hog, but it works.

Damn! I think I hurt my brain on this one! Time to go home!

Last edited by Arodicus; 06-24-2007 at 02:49 AM. Reason: Added Sample code
Arodicus is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
load textfile into textfield in amovie clip venu_31 ActionScript 2.0 1 06-30-2006 07:36 AM
textField not taking parent clip property patrickcraigmanning ActionScript 2.0 2 06-17-2006 08:29 PM
changing color of textfield inside movie clip ladyofbenjamin ActionScript 2.0 2 04-16-2005 11:39 PM
textfield in a movie clip kouri ActionScript 1.0 (and below) 2 07-15-2002 08:32 PM

All times are GMT. The time now is 10:21 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.