Jump to content


Get the selected MovieClip Instance name ?

Recommended Posts



i am trying to get the instancename of the selected item. I tryed this:


itemTransformManager.addEventListener(TransformEvent.SELECTION_CHANGE, testItemTransform);


and this:


function testItemTransform(evt:TransformEvent):void {
var item:TransformItem = itemTransformManager.getItem(evt.target as DisplayObject);

outputdata.text = String(item);


to get the instance name of the selected transform item. But this doesent work :(


Can you please tell me how i get this to work, thank you!!!

Link to comment
Share on other sites

There are several problems with your code:


1) The "target" of the SELECTION_CHANGE event would point at the TransformManager that dispatched the event - it wouldn't be a DisplayObject.


2) If you want the name of the targetObject, you wouldn't try to get that on the TransformItem. You'd get that on the TransformItem's targetObject like myItem.targetObject.name


3) Remember that a SELECTION_CHANGE event can affect multiple items, like if the user is SHIFT- or CTRL-clicking to make a multi-selection or if they had multiple items selected and then deselected everything. If you want to know the name of the first targetObject in the selection, you could do:




But remember, SELECTION_CHANGE would get dispatched when things get deselected too, so you might want to add some conditional logic in your handler like:


function mySelectionChangeHandler(event:TransformEvent):void {
   if (myManager.selectedTargetObjects.length != 0) {
       trace( myManager.selectedTargetObjects[0].name + " is selected.");
   } else {
       trace("nothing is selected.");

Link to comment
Share on other sites



thank you really much that helped great :)


But i have another question, is there an event that get fired only when you select an item(Like MOUSE_CLICK) and when you release it with the mouse(LIKE MOUSE_RELEASE)?


Thank You!

Link to comment
Share on other sites

Sure, you wouldn't really need to involve TransformManager at all in that - you could just listen directly on your DisplayObject for MOUSE_DOWN and MOUSE_UP events. Actually, it's generally better to listen for MOUSE_DOWN events and then inside that handler, listen for a MOUSE_UP event on the stage rather than the object itself just in case the user's mouse isn't over the top of the object when the user releases the mouse.


Also, you can listen for SELECT and DESELECT events on the TransformItem associated with your object if you prefer. Notice I said the TransformItem, not TransformManager.


Hope that helps!

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.