Jump to content
GreenSock

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

addSelectionBoxElement to Specific TransformItems

Recommended Posts

I am attempting to use "addSelectionBoxElement" to add an edit button to a selected object in my application. After working with it a bit, I've realized that it is a TransformManager method, so it adds that edit button to every single TransformItem associated with my TransformManager. What I am trying to do is only add the edit button to specific TransformItems (for example I have Shapes, TextField, images, etc). Is there any way to only add the edit button for specific objects, or to hide the edit button when certain objects are selected? Thanks for your help.

Link to comment
Share on other sites

Sure, you should be able to add a listener for "SELECTION_CHANGE" events and use conditional logic to change the "visible" property of your custom element based on whatever is selected (you can check the TransformManager's selectedTargetObjects array).

Link to comment
Share on other sites

Ok, I am still a bit confused on how you actually access the custom element to set its visibility? So just as a very simple example, I have the following:

 

myManager = new TransformManager();
var square:Sprite = new Sprite();
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,80,30);
square.graphics.endFill();
myManager.addSelectionBoxElement(square, "bottomRight", -80, 0);

myManager.addEventListener(TransformEvent.SELECTION_CHANGE, onselectionchange, false, 0, true);


var mcItem:TransformItem = myManager.addItem(myObject, TransformManager.SCALE_NORMAL, false);


private function onselectionchange(e:TransformEvent):void {
  //???
}

 

So, within the onselectionchange listener, how do I access the "square" from the selected object?

Link to comment
Share on other sites

Here's some pseudo code that I had in mind:

 

private function onselectionchange(e:TransformEvent):void {
   square.visible = true; // by default, we'll start with it on...
   var targets:Array = myManager.selectedTargetObjects;
   for (var i:int = 0; i < targets.length; i++) {
       if ( [your conditional logic] ) {
           square.visible = false;
       }
   }
} 

Link to comment
Share on other sites

Wow sorry, I was looking at it all the wrong way. I thought I had to access the square within the TransformItem, and trying to make it more complex than it really is. Thanks for you help.

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.
×