3 Replies Latest reply on Jul 2, 2009 12:05 AM by moutfeh5

    click event on tree icon

    bsr328
      I am trying to create a click event for just the icons of a tree (ideally, only the leaf icons, but I can deal with that logic in the event handler if need be).


      Here is my code for the custom renderer:

      package renderers{

      import mx.collections.*;
      import mx.controls.treeClasses.*;

      import mx.controls.Alert;

      import mx.core.IFlexDisplayObject;
      import mx.controls.Image;

      public class ItemViewTreeItemRenderer extends TreeItemRenderer {

      import com.ItemViewBase;
      import flash.events.MouseEvent;

      public function ItemViewTreeItemRenderer() {
      super();
      }

      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
      super.updateDisplayList(unscaledWidth, unscaledHeight);

      if(super.data) {
      super.icon.addEventListener(MouseEvent.CLICK, clickEvt);
      }
      }

      private function clickEvt(event:MouseEvent = null):void{
      Alert.show("CLICKED", "IntraVIEWER", Alert.OK, null, null, null, Alert.OK);
      }
      }
      }

      Eventually, I want to call a function outside of the renderer, but for now, I can't even successfully call the clickEvt function.

      Any ideas??? Thanks!!
        • 1. click event on tree icon
          bsr328 Level 1
          I found that this change will add the event listener only for the leaves of a tree:

          override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
          super.updateDisplayList(unscaledWidth, unscaledHeight);

          if(super.data && ! super.icon.hasEventListener(MouseEvent.CLICK)) {
          if(!TreeListData(super.listData).hasChildren){
          super.icon.addEventListener(MouseEvent.CLICK, clickEvt);
          }
          }
          }

          But the event is still not being fired when I click the icon...
          • 2. Re: click event on tree icon
            moutfeh5

            I have the same problem, i need to add an event to the icon(mouse click), i have customize all the icon in the tree through setItemIcon. Is there any problem if i customized the icon

            If u solve it please tell me how

             

            Thank you

            • 3. Re: click event on tree icon
              moutfeh5 Level 1

              Hi

               

              I found the solution

              i set mouseEnabled = true; in the construction of the inherited treeItemRenderer.

              I was using the example in the Flex CookBook, In this example at the constructor level, mouseEnabled was set to false

               

              AND in the createChildren method i add MouseEvent.Click

               

              It is written below

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

              override

               

               

               

              protected function createChildren():

               

               

              void

              {

               

               

               

               

              super.createChildren();

               

               

              super.addEventListener( MouseEvent.CLICK, imageToggleHandler);

              .....

              ...

              ....

              }

               

               

              Gd Luck