Search code examples
actionscript-3flashapache-flexflash-builder

Cannot access a method through itemRenderer using parentDocument


I have an itemRenderer inside a dataGrid, cant access to a method

<s:Module>
    <fx:Script>
      <![CDATA[

public function mysort():void{

}

]]>

...<s:panel>...

 <s:GridColumn headerText="Service Type" dataField="ServiceType" width="130"  labelFunction="labelServicePriority">
   <s:headerRenderer>
          <fx:Component>
               <s:GridItemRenderer>
                        <s:Button label="sort" click="parentDocument.mysort()"/>

                </s:GridItemRenderer>
            </fx:Component>
    </s:headerRenderer>
</s:GridColumn>
...</s:panel>...
</s:Module>

the module is within an application with a iframe


Solution

  • Here is the solution for your problem:

    I am using following way to call the method. Hope it will help you:

    <s:DataGrid id="gridTest" width="90%" height="100%" dataProvider="{tempList}" horizontalScrollPolicy="auto" >
            <s:columns>
                <mx:ArrayList>
                    <mx:source>
                        <s:GridColumn>
                            <s:itemRenderer>
                                <fx:Component>
                                    <s:GridItemRenderer width="100%" height="100%">
                                        <s:Image source="imageIcon" horizontalCenter="0" verticalCenter="0" buttonMode="true" 
                                                 click="{outerDocument.onAddIconClick(data)}"/>
                                    </s:GridItemRenderer>
                                </fx:Component>
                            </s:itemRenderer>                   
                        </s:GridColumn>
                    </mx:source>
                </mx:ArrayList>
            </s:columns>
        </s:DataGrid>
    

    Here is the function:

      public function onAddIconClick(item:Object):void
      {
        //
      }