Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
danno

trouble using getSelectionBounds

Recommended Posts

does the getSelectionBounds get applied to a TransformManager or to a TransformItem?

i believe that it's to a TransformManager, but i just can't get it correct.

 

here's what i have for when an item is scaled:

 

manager.addEventListener(TransformEvent.SCALE, managerScaled);
	function managerScaled($e:TransformEvent):void {
		trace("width is : " + myMCname.width);

	}

 

two part question.

a) is there a better way to get the selected MC better than calling it by name above? ( ie : trace("width is : " +$e.items.width);

B) if there's a better way, or with what i have above, any instruction on how to use the getSelectionBounds function?

 

thanks so much

Link to comment
Share on other sites

Keep in mind that TransformManager accommodates multiple selections, so don't assume that the event.items would only contain one item.

 

Regarding the getSelectionBounds(), it does indeed pertain to the TransformManager instance, and just like the getBounds() method, it reports the bounding box as though you drew a rectangle around the selection box. So if it is rotated, the width would be wider than if it wasn't rotated. You could use getUnrotatedSelectionWidth() if you need the...um...unrotated selection width :)

 

If you want to get the selected items' width, you could loop through the event.items Array and get each one's width or targetObject.width property.

 

Does that help?

Link to comment
Share on other sites

Regarding the getSelectionBounds(), it does indeed pertain to the TransformManager instance, and just like the getBounds() method, it reports the bounding box as though you drew a rectangle around the selection box. Does that help?

 

i think i'm a bit confused actually. here's what i've got so far, maybe you can try and point me again correctly or correct what i've got here to fix my broken logic:

 

	var manager:TransformManager = new TransformManager();

	manager.addEventListener(TransformEvent.SELECT, onManagerSelect);
	function onManagerSelect($e:TransformEvent):void
	{

		for(var i=0; i<$e.items.length; i++)
           {
              var d:DisplayObject = $e.items[i].targetObject;
              trace ("selection bounds are : " + d.getSelectionBounds());      
           }
	}

 

which is of course throwing an error.

thanks for your patience in helping me with this issue, i appreciate it.

Link to comment
Share on other sites

think i've made a bit of progress, as i think my thinking was wrong before.

here's what i have now:

 

manager.addEventListener(TransformEvent.SELECTION_CHANGE, onManagerSelect);
function onManagerSelect($e:TransformEvent):void
{
manager.selectItem($e.items[0].targetObject, true);
trace (manager.getSelectionBounds());
}

 

 

but now that i am able to trace out the getSelectionBounds() , it seems to not behave very good. if i click on the MC on my stage that has the TransformManager applied to it, all of a sudden everything on the stage disappears and the stage looks like it is entirely blank. the same results happen if i just click and drag the MC around a lot... *POOF* everything's gone.

if i resize the .swf the items on my stage reappear. very very strange.

granted, it could be that i'm not doing something correctly, what ya think?

 

**update**

this problem seems to only happening when i'm inside flash cs4 and am testing the movie ( control menu > test movie ). when uploaded to my server, this odd disappearing act isn't happening at all inside a browser.

Link to comment
Share on other sites

Not sure why everything would disappear, but your code looks like it would cause a feedback loop because you're listening for a selection event, and when that happens, you're selecting something which fires a selection event which calls your handler which changes the selection which fires a selection event, and so on. Why would you change the selection inside your handler for selection changes?

Link to comment
Share on other sites

i was misunderstanding how the "select" aspect worked. i was confused thinking that it's meaning was "when you have selected a MC by clicking on it...".

i've corrected that issue.

 

i guess this is where an example of the best practices on how to use getSelectionBounds() correctly would really help; from defining of the manager, to adding a transformItem, and with a getSelectionBounds().

 

would that be possible? thanks!

Link to comment
Share on other sites

var myManager:TransformManager = new TransformManager({targetObjects:[mc1, mc2, mc3], scaleFromCenter:true});
myManager.selectItem(mc1); //or just let the user select what they want by clicking
var bounds:Rectangle = myManager.getSelectionBounds();

 

Does that help?

 

And just for clarity, getSelectionBounds() has nothing to do with the bounds that you apply to the TransformManager to ensure that the objects stay within a certain area. getSelectionBounds() just returns a rectangle that defines the coordinates of the actual selection box at the time.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×