5 Replies Latest reply on May 17, 2012 9:42 PM by Nirmalya Saha

    Calling parent application function from ItemRenderer

    linrsvp Level 1

      Hi, I have a spark list control whose data is rendered using an  itemrenderer. Basically the Item renderer lays out the data within a  Panel.

      The Panel has a LinkButton, which when clicked needs to pass an Id to  the parent application. In the parent application I have a function  that dispatches a custom event to its parent. I want to know how to call  this function from the ItemRenderer.

      I tried using parentDocument.outerfunction etc but it throws an error..

       

      Can I do this using custom events ? If so, how ? Please explain in detail

      Thanks ,...

        • 2. Re: Calling parent application function from ItemRenderer
          linrsvp Level 1

          Yes I tried dat too.. I get an error :"Use of underfined variable" ...

          • 3. Re: Calling parent application function from ItemRenderer
            Flex harUI Adobe Employee

            Post the relevant code.

            • 4. Re: Calling parent application function from ItemRenderer
              AntuanSoft Level 1

              You can Access via

               

              parentDocument.parentDocument;

               

              MainApp.MXML:

               

              <s:Application

              ................

               

              <s:Group width="100%">

                                            <s:HGroup left="40" top="40">

               

                                                      <s:List width="100%" dataProvider="{items}"

                                                                          itemRenderer="ServicesIR"

                                                                          contentBackgroundColor="#E6E7E8" borderVisible="false">

               

                                                                <s:layout>

                                                                          <s:HorizontalLayout columnWidth="50" gap="5"/>

                                                                </s:layout>

                                                      </s:List>

               

              .....

               

              </Application>

               

              ServicesIR.mxml

               

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

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

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

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

                                                      autoDrawBackground="true">

              ...

               

              <fx:Script>

                                  <![CDATA[

               

                                            override public function set data(value:Object):void

                                            {

                                                 var parent:MainApp =  parentDocument.parentDocument; //Instance of MainApp.mxml

               

                                                 ............................

                                            }

               

              ]]>

                        </fx:Script>

               

               

                   ..............

                }

               

              <s:ToggleButton id="tab" isAlerted="false"  label="{(data.name}" horizontalCenter="0" verticalCenter="0"/>

               

               

              </s:ItemRenderer>

              • 5. Re: Calling parent application function from ItemRenderer
                Nirmalya Saha

                You can also try with FlexGlobals.topLevelApplication.parentFunction();

                And for this add ------  import  mx.core.FlexGlobals;