2 Replies Latest reply on Aug 25, 2008 7:38 PM by Newsgroup_User

    Click Event for a checkbox in a datagrid

    Astrolive
      Hi,
      I'm trying to have a checkbox contained in a daagrid to execute a function when it is clicked.
      My code is as follow

      <mx:DataGrid id="phaseDG" rowCount="{getLengthOfXmlArray(Data1XML.Phase)}" click="OnChange()" dataProvider="{Data1XML.Phase}" editable="false" x="24" y="10" width="611">
      <mx:columns>
      <mx:DataGridColumn headerText="Phase" labelFunction="FillColumns"/>
      <mx:DataGridColumn headerText="Option 1" labelFunction="FillColumns" itemRenderer="CustomBackgroundComp" textAlign="center"/>
      <mx:DataGridColumn headerText="" width="30" textAlign="center" >
      <mx:itemRenderer>
      <mx:Component>
      <mx:HBox horizontalAlign="center">
      <mx:CheckBox id="ImCB1" selected='{data.Option.(attribute("id") == "1").Imchecked == "true"}' change='data.Option.(attribute("id") == "1").Imchecked = ImCB1.selected' click="clickCB(MouseEvent.CLICK)" />
      </mx:HBox>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>

      public function initApp():void
      {
      Data1.addEventListener(MouseEvent.CLICK,clickCB);
      }

      public function clickCB(event:MouseEvent):void
      {
      DelPlus();
      impDG.visible = true;
      }

      And I get the following error: 1061: Call to a possibly undefined method clickCB through a reference with static type Class.
      Could someone tell me what I'm doing wrong and how to fix it? Some detailed explanation and/or code would be greatly appreciated (I'm a newbie). Thank you very much for your help,

      Olivia
        • 1. Re: Click Event for a checkbox in a datagrid
          atta707 Level 2
          click="outerDocument.clickCB(event)" />

          1) prefix the method name with outerDocument
          2) you acually want to pass the current event object not the constant MouseClick.CLICK

          ATTA
          • 2. Re: Click Event for a checkbox in a datagrid
            Level 7

            "Astrolive" <webforumsuser@macromedia.com> wrote in message
            news:g8v7dd$723$1@forums.macromedia.com...
            > Hi,
            > I'm trying to have a checkbox contained in a daagrid to execute a function
            > when it is clicked.
            > My code is as follow
            >
            > <mx:DataGrid id="phaseDG"
            > rowCount="{getLengthOfXmlArray(Data1XML.Phase)}"
            > click="OnChange()" dataProvider="{Data1XML.Phase}" editable="false" x="24"
            > y="10" width="611">
            > <mx:columns>
            > <mx:DataGridColumn headerText="Phase" labelFunction="FillColumns"/>
            > <mx:DataGridColumn headerText="Option 1" labelFunction="FillColumns"
            > itemRenderer="CustomBackgroundComp" textAlign="center"/>
            > <mx:DataGridColumn headerText="" width="30" textAlign="center" >
            > <mx:itemRenderer>
            > <mx:Component>
            > <mx:HBox horizontalAlign="center">
            > <mx:CheckBox id="ImCB1" selected='{data.Option.(attribute("id") ==
            > "1").Imchecked == "true"}' change='data.Option.(attribute("id") ==
            > "1").Imchecked = ImCB1.selected' click="clickCB(MouseEvent.CLICK)" />
            > </mx:HBox>
            > </mx:Component>
            > </mx:itemRenderer>
            > </mx:DataGridColumn>
            >
            > public function initApp():void
            > {
            > Data1.addEventListener(MouseEvent.CLICK,clickCB);
            > }
            >
            > public function clickCB(event:MouseEvent):void
            > {
            > DelPlus();
            > impDG.visible = true;
            > }
            >
            > And I get the following error: 1061: Call to a possibly undefined method
            > clickCB through a reference with static type Class.
            > Could someone tell me what I'm doing wrong and how to fix it? Some
            > detailed
            > explanation and/or code would be greatly appreciated (I'm a newbie). Thank
            > you
            > very much for your help,

            http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html?devcon=f1