1 Reply Latest reply on Feb 8, 2012 6:47 PM by lailinhan

    Simulate itemClick event for mx:tree object

    lailinhan

      Hi,

       

      I want to simulate itemClick event for mx:tree object after I click a button.  But neither ListEvent nor ItemClickEvent works. Please see my code:

      <mx:Tree id="myTree"

                           showRoot="true"

                           width="100%"

                           height="100%"

                           dataProvider="{myCollection}"

                           itemClick="handleItemClick(event)"

                           fontSize="12" backgroundAlpha="0"

                           borderStyle="none"

                           styleName="adminTree"

                           paddingLeft="30"

                           selectedIndex="0"

                           useHandCursor="true" buttonMode="true" />

       

      <mx:Button id="myBtn" label="Open item 1" click="handleClickMyBtn(event)" useHandCursor="true" buttonMode="true"/>

      private function handleClickMyBtn(event:MouseEvent):void

                  {

       

                      var evt:ListEvent = new ListEvent(ListEvent.ITEM_CLICK,false,false,0,1,null);

                      evt.itemRenderer.data=myCollection.getItemAt(1);

                      myTree.selectedIndex=1;

                     myTree.dispatchEvent(evt);

                  }

       

      After I click myBtn, the item 1 of myTree will be selected, but the "handleItemClick(event)" function is not called, that means dispatchEvent(evt) in handleClickMyBtn does not work.

       

      And it does not work either if I use ItemClickEvent:

       

      private function handleClickMyBtn(event:MouseEvent):void

                  {

       

                     var evt:ItemClickEvent = new ItemClickEvent(ItemClickEvent.ITEM_CLICK,false,false,"Item 1 Label",1,null,myTree.dataProvider[1]);

                     myTree.dispatchEvent(evt);

                  }

       

      Who can tell me how to make the Item_Click event was dispatched to mx:tree??? Many thanks.

       

      btw: myCollection is  ArrayCollection, each item in it has .label and .view properties.