Adobe Dreamweaver Forums



Last 10 THreads :         Live stream player (Last Post : noobie_here - Replies : 0 - Views : 1 )           »          cfloop within a cfif tag (Last Post : Azadi - Replies : 2 - Views : 3 )           »          Making constraints on a symbol... (Last Post : sirkibble2 - Replies : 0 - Views : 1 )           »          Creating a boundry in the stage... (Last Post : fazstp - Replies : 2 - Views : 3 )           »          Director or Flash? (Last Post : Sean Wilson - Replies : 1 - Views : 2 )           »          DW8 Activation not working (Last Post : moonliner - Replies : 0 - Views : 1 )           »          Re: Mouse capture won't activate (Last Post : robertnagle - Replies : 0 - Views : 1 )           »          help! my FB3 has gone insane! (Last Post : peteandrus - Replies : 0 - Views : 1 )           »          help! my FB3 has gone insane! (Last Post : peteandrus - Replies : 0 - Views : 1 )           »          How come the html is being displayed, and not the link (Last Post : Skaterstu - Replies : 0 - Views : 1 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags: , , , , ,



Reply
  #1 (permalink)  
Old 09-04-2008, 09:12 PM
ericbelair
 
Posts: n/a
Diggs:
Default Alert Causes Tree to Invoke Item Editor

Attached is a very simplified version of my application which is causing me a
headache. I have a Tree to which I have added a custom ContextMenu, with
options to Delete and Rename items in the Tree. When a user selects "Delete", I
force them to confirm the deletion by showing an Alert, with YES/NO options.
However, regardless of what option they choose, when they click one of the
buttons, the Tree suddenly shows one of the items in edit mode. I can't
understand why.

To reproduce:
1. Compile the attached code in a Flex Project and open the application in a
browser.
2. Open the "Parent" node in the Tree.
3. Select the "Child" node.
4. Right-click with your mouse in the Tree and select Delete.
5. Select either Yes or No.

Any help with preventing this behavior from happening would be greatly
appreciated.

Thank you.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
styleName="plain">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.listClasses.IListItemRenderer;
import mx.events.CloseEvent;
import mx.events.ListEvent;
import mx.events.ListEventReason;

[Bindable]
public var reportContainers:ArrayCollection =
new ArrayCollection([{name: "Parent", children: [{name:
"Child"}]}]);

private var myTreeIsRendered:Boolean = false;

private function myTree_renderHandler():void
{
/* Perform this logic only once - the first time the component
is
rendered. */
if (!myTreeIsRendered)
{
myTreeIsRendered = true;

createContextMenu();
}
}

private function createContextMenu():void
{
var contextMenu:ContextMenu = new ContextMenu();

contextMenu.hideBuiltInItems();

contextMenu.addEventListener(ContextMenuEvent.MENU _SELECT,
contextMenu_menuSelectHandler);

myTree.contextMenu = contextMenu;
}

private function
contextMenu_menuSelectHandler(event:ContextMenuEve nt):void
{
/* If an item is being edited, end the item edit, before
allowing any
other items to be added or removed, by manually
dispatching an
itemEditEnd Event. */
if (myTree.editedItemPosition != null)
{
var editedItemRenderer:IListItemRenderer =
myTree.editedItemRenderer as IListItemRenderer;

var itemEditEndEvent:ListEvent =
new ListEvent(ListEvent.ITEM_EDIT_END, false, false,
0,

myTree.editedItemPosition.rowIndex,
ListEventReason.CANCELLED,
editedItemRenderer);

myTree.dispatchEvent(itemEditEndEvent);
}

myTree.contextMenu.customItems = [];

var deleteMenuItem:ContextMenuItem =
new ContextMenuItem("Delete...", false);


deleteMenuItem.addEventListener(ContextMenuEvent.M ENU_ITEM_SELECT,
deleteMenuItem_menuItemSelectHandler);

myTree.contextMenu.customItems.push(deleteMenuItem );

var isRenameEnabled:Boolean = (myTree.selectedIndex != -1);

var renameMenuItem:ContextMenuItem =
new ContextMenuItem("Rename...", false, isRenameEnabled);


renameMenuItem.addEventListener(ContextMenuEvent.M ENU_ITEM_SELECT,
renameMenuItem_menuItemSelectHandler);

myTree.contextMenu.customItems.push(renameMenuItem );
}

private function
deleteMenuItem_menuItemSelectHandler(event:Context MenuEvent):void
{
var confirmText:String = "Are you sure you want to " +
"completely remove the selected Item?";

Alert.show(confirmText, "Confirm Delete", Alert.YES |
Alert.NO, this,
confirmRemove_closeHandler);
}

private function confirmRemove_closeHandler(event:CloseEvent):void
{

}

// Manually dispatches an itemEditBeginning Event with a custom
reason
private function
renameMenuItem_menuItemSelectHandler(event:Context MenuEvent):void
{
var itemRenderer:IListItemRenderer = myTree.itemRenderer as
IListItemRenderer;

var itemEditBeginningEvent:ListEvent =
new ListEvent(ListEvent.ITEM_EDIT_BEGINNING, false, false,
0,
myTree.selectedIndex,
"contextMenuRename", itemRenderer);

myTree.dispatchEvent(itemEditBeginningEvent);
}

private function
myTree_itemEditBeginningHandler(event:ListEvent):v oid
{
if (event.reason != "contextMenuRename")
event.preventDefault();
}

]]>
</mx:Script>
<mx:Tree id="myTree" width="100%" height="100%" editable="true"
dataProvider="{reportContainers}" labelField="name"
allowMultipleSelection="false"
render="myTree_renderHandler();"
itemEditBeginning="myTree_itemEditBeginningHandler (event);"/>
</mx:Application>



Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 02:39 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk