0 Replies Latest reply on Aug 15, 2007 11:01 AM by kleber.kiefer

    setFocus - Tree edit mode

    kleber.kiefer
      Hello guys,

      I need (again) your help!!!

      How to I set focus (select text) when the Tree Item is in edit mode???
      I searched in web, but I could'nt find it.

      See my code:

      =====================================================================
      editTree.mxml
      =====================================================================

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:Script>
      <![CDATA[

      import mx.managers.CursorManager;
      import mx.core.UIComponent;
      import mx.controls.Tree;
      import mx.controls.listClasses.IListItemRenderer;
      import mx.events.ListEvent;
      import myComponents.TreeEditor;

      private function disableEditing(event:ListEvent):void {
      if (event.rowIndex==0) {
      event.preventDefault();
      }
      }

      public function processData(event:ListEvent):void {
      event.preventDefault();
      tree.editedItemRenderer.data.@label = TreeEditor(event.currentTarget.itemEditorInstance).playlistName.text;
      tree.destroyItemEditor();
      tree.dataProvider.notifyItemUpdate(tree.editedItemRenderer);
      }

      ]]>
      </mx:Script>

      <mx:Style>
      Tree {
      backgroundAlpha: 0;
      borderStyle: none;
      indentation: 6;
      }

      TextInput {
      borderStyle: none;
      backgroundAlpha: 0;
      focusThickness: 1;
      }
      </mx:Style>

      <mx:XML id="treeData" xmlns="">
      <node label="PLAYLIST" type="lists" data="MA">
      <node label="Musics" type="list" />
      <node label="My Top Musics" type="list" />
      <node label="Recently Added" type="list" />
      </node>
      </mx:XML>

      <mx:Panel width="350" height="350" title="Edit">

      <mx:Tree id="tree"
      width="200"
      height="220"
      dataProvider="{treeData}"
      labelField="@label"
      editable="true"
      itemEditor="myComponents.TreeEditor"
      itemEditBeginning="disableEditing(event);"
      itemEditEnd="processData(event);" >
      </mx:Tree>

      </mx:Panel>

      </mx:Application>

      =====================================================================

      and...

      =====================================================================
      TreeEditor.mxml
      =====================================================================

      <?xml version="1.0" encoding="iso-8859-1"?>

      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml"
      implements="mx.managers.IFocusManagerComponent">

      <mx:Script>
      <![CDATA[
      public var newName:String;

      override public function drawFocus(isFocused:Boolean):void {
      // This method can be empty, or you can use it
      // to make a visual change to the component.
      }
      ]]>
      </mx:Script>

      <mx:TextInput id="playlistName"
      text="{data.@label}"
      backgroundAlpha="1"
      height="18"
      change="newName=playlistName.text;" />

      </mx:VBox>

      =====================================================================

      Thanks!!!

      Kleber