Flex 4 need help Deleting objects from the Canvas

49 views
Skip to first unread message

Craig McLeod

unread,
Sep 1, 2011, 4:59:51 AM9/1/11
to Flex ObjectHandles
Hi,

I am adding objects to the canvas dynamically and then when I want to
delete them I use the following code:

public function removeSelected():void {
if (objectHandles.selectionManager.currentlySelected[0])
{
var elementToRemove:IVisualElement;
try {
elementToRemove =
this[objectHandles.selectionManager.currentlySelected[0].CanvasItemID];
objectHandles.unregisterComponent(elementToRemove);
mainGroup.removeElement(elementToRemove)
} catch (myE:Error){
//Alert.show
([objectHandles.selectionManager.currentlySelected[0].CanvasItemID] +
'')
//elementToRemove =
[objectHandles.selectionManager.currentlySelected[0].CanvasItemID] ;
//objectHandles.unregisterComponent(elementToRemove);
//mainGroup.removeElement(elementToRemove)

Alert.show(mainGroup[objectHandles.selectionManager.currentlySelected[0].CanvasItemID]
+ '');
}


} else {
Alert.show('Please select an object to remove from the
canvas','Oops');
}
}

It only seems to work for objects that start off on the stage, it
fails for new objects even though they have the same address space.

Anyone got a working example of how to delete objects off the stage in
FLEX 4.

Please and thank you for any help you can offer.

Regards
Craig

Reply all
Reply to author
Forward
0 new messages