1 Reply Latest reply on Jul 31, 2007 1:56 PM by Peter deHaan

    [Flex3/AIR] problem with HeaderRenderer and Button

    mightydev
      HI

      i tried to do 2 different ways to use the button within HeaderRenderer
      i wanted to insert a button into DataGridColoum by HeaderRenderer field and when i click on this i get this error
      What wrong about my code ?

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at mx.controls:ataGrid/mx.controlsataGrid::focusInHandler()
      at flash.display::Stage/set focus()
      at mx.core::UIComponent/setFocus()
      at mx.managers::FocusManager/setFocus()
      at mx.managers::FocusManager/::mouseDownHandler()

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

      Component myCanvasHeader

      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" horizontalAlign="center" >
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;

      import mx.core.Application;
      import flash.events.MouseEvent;

      private function clickme(e:MouseEvent):void {
      Alert('allo');
      }

      ]]>
      </mx:Script>

      <mx:Canvas>
      <mx:Button id="bt" label="click me"
      buttonMode="true" useHandCursor="true"
      click="clickme(event)"/>
      </mx:Canvas>

      </mx:VBox>


      Class myHeader

      package
      {
      import mx.controls.Button;
      import flash.events.MouseEvent;
      import mx.controls.dataGridClasses.DataGridColumn;
      import flash.events.Event;

      public class myHeader extends Button {

      public function myHeader():void {
      super();
      label = "click me 2";
      this.addEventListener(MouseEvent.CLICK,onClickHandler);
      }
      override public function set data(value:Object):void
      {
      if(value is DataGridColumn){
      //do not call super; that is it!!
      }
      else{
      super.data = value;
      }
      }
      private function onClickHandler(event:MouseEvent):void {
      dispatchEvent(new Event("headerButtonClicked",true));
      }
      }
      }

      MainApplication

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      creationComplete="init()">
      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;

      private function init():void {
      addEventListener("headerButtonClicked",headerClicked);
      }

      private function headerClicked(e:Event):void {
      Alert("Button clicked");
      }

      ]]>
      </mx:Script>

      <mxanel title="DataGrid Control Example" height="100%" width="100%" paddingTop="10" paddingLeft="10" paddingRight="10">

      <mxataGrid id="dg" sortableColumns="false" draggableColumns="false">
      <mx:columns>
      <mxataGridColumn headerRenderer="views.myCanvasHeader"/>
      <mxataGridColumn headerRenderer="myHeader"/>
      </mx:columns>
      </mxataGrid>

      </mxanel>
      </mx:Application>