4 Replies Latest reply on Mar 24, 2009 5:38 AM by Newsgroup_User

    passing variables between itemrenderer and main application

    san00001
      Hi,
      I am using itemrenderers.We can access main application's variables inside the itemrenderer using outerdocument.variablename.
      But how can i access the variable inside the itemrenderer in the main application?
      Any one pls help me

        • 1. passing variables between itemrenderer and main application
          Gregory Lafrance Level 6
          itemRenderers are recycled, so not good to rely on their variable values. Show simplified yet complete example and maybe we can suggest modifications.
          • 2. Re: passing variables between itemrenderer and main application
            san00001 Level 1
            This is my code

            <mx:DataGrid id="tasks1" color="black" height="266" resizableColumns="false" sortableColumns="false"
            borderThickness="0" width="100%" headerHeight="45" textAlign="center"

            variableRowHeight="true" alpha="2" x="0" y="0">
            <mx:columns>
            <mx:DataGridColumn id="task1" width="85" dataField="taskName" headerText="Tasks" textAlign="left" >
            <mx:headerRenderer>

            <mx:Component>
            <mx:HBox clipContent="false">



            <mx:Label id="myLabel" fontWeight="normal" color="navy" textAlign="center" height="45" width="85" initialize="myLabel_initialize()"/>
            <mx:Script>
            <![CDATA[
            private function myLabel_initialize():void {
            myLabel.htmlText = "Tasks\nAssigned";
            }
            ]]>
            </mx:Script>
            </mx:HBox>
            </mx:Component>
            </mx:headerRenderer>
            <mx:itemRenderer>
            <mx:Component>
            <mx:HBox>
            <mx:List id="list1" themeColor="white" allowMultipleSelection="false" width="85" creationComplete="{setTaskflag();}" height="20" rowHeight="20" borderThickness="0" />
            <mx:Script>
            <![CDATA[
            import mx.controls.List;
            import mx.controls.Alert;
            import mx.styles.StyleManager;
            import mx.events.FlexEvent;
            import mx.events.DragEvent;
            import mx.collections.ArrayCollection;
            import com.zensar.jobcard.TaskListVO;
            import mx.events.ItemClickEvent;
            import mx.events.FlexEvent;
            import mx.events.StateChangeEvent;
            import mx.events.ListEvent;
            import mx.controls.TextInput;
            var str:String=new String();
            var newVal=new String();


            ]]>
            </mx:Script>
            </mx:HBox>
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
            i want to use the variables in the innerscript outside the item renderer
            • 3. Re: passing variables between itemrenderer and main application
              Level 7

              "san00001" <webforumsuser@macromedia.com> wrote in message
              news:gq7eeq$81$1@forums.macromedia.com...
              > Hi,
              > I am using itemrenderers.We can access main application's variables inside
              > the
              > itemrenderer using outerdocument.variablename.
              > But how can i access the variable inside the itemrenderer in the main
              > application?
              > Any one pls help me

              Any event that is dispatched that involves your renderer (custom or
              built-in, such as itemClicked) will contain a reference to your renderer in
              event.target or event.currentTarget. Once you have a reference to the
              renderer, it is easy to get its public properties or call a method on it
              that returns a value.

              HTH;

              Amy


              • 4. Re: passing variables between itemrenderer and main application
                Level 7

                "san00001" <webforumsuser@macromedia.com> wrote in message
                news:gq841m$r29$1@forums.macromedia.com...
                > This is my code

                > i want to use the variables in the innerscript outside the item renderer

                Check out Q2 for info about why you don't want to be setting variables in
                creationcomplete:
                http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf

                But to answer your question, any components that you define in mxml will be
                public, as will any variables you make public.

                So in an event handler for an event from your first renderer, you could say:

                var text:String = (event.currentTarget.myLabel as Label).htmlText

                Note that you might also want to consider using a labelFunction rather than
                a custom item renderer on that one.

                Your second renderer doesn't appear to have the setTaskFlag() function you
                are trying to call, but if you wanted to access the variables within it, you
                could do something like this:

                public var str:String=new String();
                public var newVal=new String();

                and then in the event handler

                var text:string = event.currentTarget['str'];

                Unfortunately when you use inline components, you can't use type checking
                for properties of the component.

                HTH;

                Amy