2011-06-12 90 views
1

當用戶右鍵單擊某個按鈕時,將顯示「刪除」上下文菜單項。如果用戶點擊「刪除」選項,該按鈕應該從其瓷磚父容器中移除。我將如何使用Flex 3和ActionScript 3實現這一點?右鍵菜單上的刪除按鈕選項

回答

1

你需要創建一個自定義flash.ui.ContextMenu,向其中添加一個ContextMenuItem對應刪除你希望用戶選擇文本。

添加一個事件監聽器到這個ContextMenuItem,它將處理移除被點擊的項目。下面是實現去除的一種方法:

private function removeItemHandler(event:ContextMenuEvent):void 
    { 
    ((event.mouseTarget as DisplayObject).parent as DisplayObjectContainer).removeChild((event.mouseTarget as DisplayObject)); 
    Alert.show((event.mouseTarget.toString() + " has been removed."),"Display Object Removed"); 
    } 

最後,確保設置要ContextMenu你創建的是可移動的定製所有組件的contextMenu財產(InteractiveObject的)。

的上面的代碼對應於Flex 3中,由於問題指定。對於Flex 4,分別使用IVisualElement,IVisualElementContainerremoveElement方法代替DisplayObjectDisplayObjectContainerremoveChild方法。

相關問題