0 Replies Latest reply on Nov 5, 2012 5:24 AM by Sonunew2flex

    Header renderer click handler not working

    Sonunew2flex

      Hi All

       

      Below is code of my header renderer which copied code from default headerrenderer and created new one, I added textinput with down arrow and close button,

       

      But when i click on close button, I am making filter box invisible, If i put a break point inside griditemrenderer1_mouseOutHandler() function then filter box becomes invisible, but while running in debug mode without break point filter box shows visible only,

       

      Please let me know where i am doing wrong.

       

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

       

       

      <s:GridItemRenderer minWidth="21" minHeight="21"

                          xmlns:fx="http://ns.adobe.com/mxml/2009"

                          xmlns:s="library://ns.adobe.com/flex/spark"

                          xmlns:mx="library://ns.adobe.com/flex/mx"

                          mouseOver="griditemrenderer1_mouseOverHandler(event)"

                          creationComplete="griditemrenderer1_creationCompleteHandler(event)">

         

          <fx:Declarations>

              <s:Label id="labelDisplay"

                       verticalCenter="1"

                       textAlign="start"

                       fontWeight="bold"

                       verticalAlign="middle"

                       maxDisplayedLines="1"

                       showTruncationTip="true" />

             

          </fx:Declarations>

         

          <fx:Script>

              <![CDATA[

                  import com.db.view.components.FilterPopup;

                  import mx.managers.PopUpManager;

                  import mx.controls.Menu;

                  import mx.events.FlexEvent;

                  import spark.components.gridClasses.IGridVisualElement;

                  import mx.core.IVisualElement;

                 

                  import spark.components.DataGrid;

                  import spark.components.GridColumnHeaderGroup;

                  import spark.components.gridClasses.GridColumn;

                  import spark.primitives.supportClasses.GraphicElement;

                 

                  // chrome color constants and variables

                  private static const DEFAULT_COLOR_VALUE:uint = 0xCC;

                  private static const DEFAULT_COLOR:uint = 0xCCCCCC;

                  private static const DEFAULT_SYMBOL_COLOR:uint = 0x000000;

                 

                  private static var colorTransform:ColorTransform = new ColorTransform();

                 

                  /**

                   *  @private

                   */

                  private function dispatchChangeEvent(type:String):void

                  {

                      if (hasEventListener(type))

                          dispatchEvent(new Event(type));

                  }           

                 

                  //----------------------------------

                  //  maxDisplayedLines

                  //----------------------------------

                 

                  private var _maxDisplayedLines:int = 1;

                 

                  [Bindable("maxDisplayedLinesChanged")]

                  [Inspectable(minValue="-1")]

                 

                  /**

                   *  The value of this property is used to initialize the

                   *  <code>maxDisplayedLines</code> property of this renderer's

                   *  <code>labelDisplay</code> element.

                   *

                   *  @copy spark.components.supportClasses.TextBase#maxDisplayedLines

                   *

                   *  @default 1

                   *

                   *  @langversion 3.0

                   *  @playerversion Flash 10

                   *  @playerversion AIR 1.5

                   *  @productversion Flex 4.5

                   */

                  public function get maxDisplayedLines():int

                  {

                      return _maxDisplayedLines;

                  }

                 

                  /**

                   *  @private

                   */

                  public function set maxDisplayedLines(value:int):void

                  {

                      if (value == _maxDisplayedLines)

                          return;

                     

                      _maxDisplayedLines = value;

                      if (labelDisplay)

                          labelDisplay.maxDisplayedLines = value;

                     

                      invalidateSize();

                      invalidateDisplayList();

                     

                      dispatchChangeEvent("maxDisplayedLinesChanged");

                  }

                 

       

                  /**

                   *  @private

                   *  Create and add the sortIndicator to the sortIndicatorGroup and the

                   *  labelDisplay into the labelDisplayGroup.

                   */

                  override public function prepare(hasBeenRecycled:Boolean):void

                  {

                      super.prepare(hasBeenRecycled);

                     

                      if (labelDisplay && labelDisplayGroup && (labelDisplay.parent != labelDisplayGroup))

                      {

                          labelDisplayGroup.removeAllElements();

                          labelDisplayGroup.addElement(labelDisplay);

                      }

                     

          

                  }

                 

                  private var chromeColorChanged:Boolean = false;

                  private var colorized:Boolean = false;

                 

                  [Bindable]

                  private var _filterVisibility:Boolean = false;

                  /**

                   *  @private

                   *  Apply chromeColor style.

                   */

                  override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void

                  {

                      // Apply chrome color

                      if (chromeColorChanged)

                      {

                          var chromeColor:uint = getStyle("chromeColor");

                         

                          if (chromeColor != DEFAULT_COLOR || colorized)

                          {         

                              colorTransform.redOffset = ((chromeColor & (0xFF << 16)) >> 16) - DEFAULT_COLOR_VALUE;

                              colorTransform.greenOffset = ((chromeColor & (0xFF << 8)) >> 8) - DEFAULT_COLOR_VALUE;

                              colorTransform.blueOffset = (chromeColor & 0xFF) - DEFAULT_COLOR_VALUE;

                              colorTransform.alphaMultiplier = alpha;

                             

                              transform.colorTransform = colorTransform;

                             

                              var exclusions:Array = [labelDisplay];

                             

                              // Apply inverse colorizing to exclusions

                              if (exclusions && exclusions.length > 0)

                              {

                                  colorTransform.redOffset = -colorTransform.redOffset;

                                  colorTransform.greenOffset = -colorTransform.greenOffset;

                                  colorTransform.blueOffset = -colorTransform.blueOffset;

                                 

                                  for (var i:int = 0; i < exclusions.length; i++)

                                  {

                                      var exclusionObject:Object = exclusions[i];

                                     

                                      if (exclusionObject &&

                                          (exclusionObject is DisplayObject ||

                                              exclusionObject is GraphicElement))

                                      {

                                          colorTransform.alphaMultiplier = exclusionObject.alpha;

                                          exclusionObject.transform.colorTransform = colorTransform;

                                      }

                                  }

                              }

                             

                              colorized = true;

                          }

                         

                          chromeColorChanged = false;

                      }

                     

                      super.updateDisplayList(unscaledWidth, unscaledHeight);

                  }

                 

                  /**

                   *  @private

                   */

                  override public function styleChanged(styleProp:String):void

                  {

                      var allStyles:Boolean = !styleProp || styleProp == "styleName";

                     

                      super.styleChanged(styleProp);

                     

                      if (allStyles || styleProp == "chromeColor")

                      {

                          chromeColorChanged = true;

                          invalidateDisplayList();

                      }

                  }

                 

                  protected function griditemrenderer1_mouseOverHandler(event:MouseEvent):void

                  {

                      _filterVisibility = true;

                  }

                 

                  protected function griditemrenderer1_mouseOutHandler():void

                  {

                      _filterVisibility = false;

                     

                  }

                 

                  protected function griditemrenderer1_creationCompleteHandler(event:FlexEvent):void

                  {

                      trace(label);

                     

                  }

                 

                  protected function textinput1_clickHandler(event:MouseEvent):void

                  {

                      var filterpopUp:FilterPopup = new FilterPopup();

                      filterpopUp.filterColumn = label;

                      PopUpManager.addPopUp(filterpopUp,this,false);

                      filterpopUp.addEventListener("test",testHandler);

                      filterpopUp.x = event.stageX - 50;

                      filterpopUp.y = event.stageY + 10;

                  }

                 

                  protected function testHandler(event:Event):void

                  {

                      owner.dispatchEvent(new Event("test"));

                  }

                 

              ]]>

          </fx:Script>

         

         

          <s:VGroup left="7" right="7" top="5" bottom="5" gap="2" verticalAlign="bottom">

             

              <s:HGroup id="tiFilter" width="100%" gap="3" verticalAlign="middle" visible="{_filterVisibility}">

                  <s:TextInput width="{labelDisplay.width + 20}" height="16" skinClass="com.db.view.skins.FilterTextInputSkin"

                                text="{label}" click="textinput1_clickHandler(event)"/>

                  <s:HGroup id="closeBtn" width="15" height="15" click="griditemrenderer1_mouseOutHandler()"

                            buttonMode="true" useHandCursor="true" mouseChildren="false" keyDown="griditemrenderer1_mouseOutHandler()">

                      <s:Image source="@Embed('/assets/images/icon_close.gif')"/>

                  </s:HGroup>

              </s:HGroup>

       

             

              <s:Group id="labelDisplayGroup" width="100%"/>

             

              <s:Group id="sortIndicatorGroup" includeInLayout="false" />

             

          </s:VGroup>

         

      </s:GridItemRenderer>