Jump to content
GreenSock

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

Object Index and Object Removal

Recommended Posts

Hi!

 

I'm trying to create an interactive board for kids, and I seem to be having a problem with two things

1. setting the transformable object's index

2. deleting the objects off the stage when clicking on other frames

 

 

The first problem is that when I'm adding shapes to the stage, they're being placed on top of menus etc, I want their index to be lowered.. by several depths, right now they're at 20 (tracing childindex) Is there a way to set their depth? I tried addChildAt but it didn't seem to work..Also tried moveSelectionDepthDown, and traced the child index but it didn't change.

 

function addSquare(e:MouseEvent):void {

 

addChild(newSquare);

//addChildAt(newSquare,0);

manager.addItem(newSquare);

manager.moveSelectionDepthDown();

manager.selectItem(newSquare);

newSquare.buttonMode=true;

}

 

 

The second issue is deleting the shapes off the stage, I'm calling the code below when a clear all button is clicked, and it works perfectly fine. But I've also placed the same code on other frames, so that when the user navigates to another section without pressing on the clear all button, the shapes still won't show. However, if no shapes are already on the stage, I get a runtime error. Is there a way to know if the shapes are not the stage or not, before attempting to remove them? Or any easier way to do this?

 

 

manager.selectItems(manager.items);

manager.deleteSelection();

manager.removeAllItems();

 

 

 

Any help is appreciated, thank u!

Link to comment
Share on other sites

You can set a DisplayObject's index with its parent's setChildIndex()

 

myObject.parent.setChildIndex(myObject, 1);

 

As for the code that deletes objects, that works fine for me. If you're running into errors I wonder if there's something else going on in your code (tough to say without being able to compile a sample file that demonstrates the issue). If you're still having trouble, could you post an example FLA or Flex project? The simpler the better.

Link to comment
Share on other sites

I tried using the parent setChildIndex (), but it still didn't work.

 

I did a sample fla that shows the index problem, and the runtime error when you click on a section that doesn't have any loaded instances yet.

 

 

Thank you so much!

Link to comment
Share on other sites

By default, TransformManager automatically brings the selection to the front. If you want to manually set the index, all you need to do is set the manager's "forceSelectionToFront" property to false.

 

manager.forceSelectionToFront = false;

 

As far as the error goes, that doesn't appear to have anything to do with TransformManager - you just need to check for null references when you try doing stuff like getChildIndex() (you can't get the index of a null object or one that's not a child of that parent). See what I mean? So instead of this:

 

getChildIndex(newSquare);

 

you'd do this:

 

if (newSquare != null && this.contains(newSquare)) {
   getChildIndex(newSquare);
}

Link to comment
Share on other sites

Thank you so much, the force selection worked perfectly, I'm still dabbling with the other part.

 

i have one last question, when I try to rotate and scale the objects, the drawing functionality still works. Do the handles listen for events as well? I tried using the transform event listeners but it's still drawing all over the place. Is there something else I need to listen for?

 

newSquare.addEventListener(TransformEvent.SEIZE_CURSOR, stopdraw);

newSquare.addEventListener(TransformEvent.START_INTERACTIVE_SCALE, stopdraw);

newSquare.addEventListener(TransformEvent.START_INTERACTIVE_MOVE, stopdraw);

newSquare.addEventListener(TransformEvent.START_INTERACTIVE_ROTATE, stopdraw);

newSquare.addEventListener(TransformEvent.FINISH_INTERACTIVE_SCALE, startdraw);

newSquare.addEventListener(TransformEvent.FINISH_INTERACTIVE_MOVE, startdraw);

newSquare.addEventListener(TransformEvent.FINISH_INTERACTIVE_ROTATE, startdraw);

newSquare.addEventListener(TransformEvent.MOVE, stopdraw);

newSquare.addEventListener(TransformEvent.SCALE, stopdraw);

newSquare.addEventListener(TransformEvent.ROTATE, stopdraw);

 

newSquare.addEventListener(MouseEvent.MOUSE_DOWN, stopdraw);

newSquare.addEventListener(MouseEvent.MOUSE_UP, startdraw);

 

function stopdraw(e:MouseEvent):void {

stage.removeEventListener(MouseEvent.MOUSE_DOWN, startDrawing);

drawIt = false;

 

}

function startdraw(e:MouseEvent):void {

 

stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);

 

drawIt = true;

}

 

 

Link to comment
Share on other sites

I don't see anything obvious, no. Maybe try adding a trace() to both functions to see if/when they're getting called. trace() the event.type too so you know which ones are responsible.

Link to comment
Share on other sites

  • 1 month later...

You'd have to hijack the mouse events inside the transformmanagers mousedown/up (when you start to rotate etc) and do e.stopImmedatePropagation() to prevent the mouseevent to bubble down to your drawing app.

 

quick fix, I'm sure you can figure it out :)

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