You can try getObjectsUnderPoint (use mouseX/Y to get stage coordinates).  Your 
custom container should be in the array it returns.

Alex Harui
Flex SDK Developer
Adobe Systems Inc.<http://www.adobe.com/>
Blog: http://blogs.adobe.com/aharui

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of jmfillman
Sent: Wednesday, September 02, 2009 11:27 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Context Menu mouseTarget Issue



This worked:

myCanvas.removeChildAt(myCanvas.getChildIndex(event.mouseTarget));

and

myCanvas.removeChildAt(myCanvas.getChildIndex(event.mouseTarget.parent));

depending on whether the mouse is over the root Panel component or the child 
containers added to the panel.

The harder part is identifying which item in my ArrayCollection corresponds to 
the mouseTarget. What I've ended up doing is capturing the parent/child path 
(E.g. TestApp0.canvasShell.myCanvas.myContainer592) in my ArrayCollection, then 
looping until I find a match and removing that item. Is there a more efficient 
way?

--- In flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>, Alex 
Harui <aha...@...> wrote:
>
> What is event.mouseTarget? and what is its parent? You might be off a level 
> or two.
>
> Alex Harui
> Flex SDK Developer
> Adobe Systems Inc.<http://www.adobe.com/>
> Blog: http://blogs.adobe.com/aharui
>
> From: flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com> 
> [mailto:flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>] On 
> Behalf Of jmfillman
> Sent: Tuesday, September 01, 2009 2:01 PM
> To: flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>
> Subject: [flexcoders] Context Menu mouseTarget Issue
>
>
>
> I have a canvas container with several custom containers added to it. I have 
> a context menu so that when you right click on the containers, you can remove 
> it from the canvas container. When I go to remove a child, I get an error, 
> below.
>
> Code:
> private function menuSelectHandler(event:ContextMenuEvent):void {
> var remChild:Number;
> var target:String = event.mouseTarget.toString();
> trace (target);
> if (target.match("UIComponent") == null && target.match("resizeBar") == null) 
> {
> trace (" True 1");
> trace (" "+event.mouseTarget);
> remChild = cal0Day.getChildIndex(event.mouseTarget);
>
> }
> else {
> trace (" True 2");
> trace (" "+event.mouseTarget.parent);
> remChild = myCanvas.getChildIndex(event.mouseTarget.parent);
> }
> trace (remChild);
> trace (myCanvas.getChildAt(remChild));
> myCanvas.removeChildAt(remChild);
> myAC.removeChildAt(remChild);
> updateLayout();
> }
>
> TestApp0.canvasShell.myCanvas.myContainer592
> True 1
> TestApp0.canvasShell.myCanvas.myContainer592
> 12
> TestApp0.canvasShell.myCanvas.myContainer592
>
> Then I get the following error:
> ArgumentError: Error #2025: The supplied DisplayObject must be a child of the 
> caller.
> at flash.display::DisplayObjectContainer/getChildIndex()
>
> How do I do this?
>

Reply via email to