3 Replies Latest reply on Jun 8, 2008 8:32 AM by NateBaldwin

    Parent to ItemRenderer Communication

    NateBaldwin Level 3
      The title pretty much says it all: how do you access the value of a variable in the parent document from an ActionScript (no MXML) item renderer (it's in an AdvancedDataGrid, if it matters). Thanks in advance.
        • 1. Re: Parent to ItemRenderer Communication
          atta707 Level 2
          what about this.parent["parentProp"]? Could you please show some code snippet explaining what problem you're trying to solve?
          • 2. Re: Parent to ItemRenderer Communication
            NateBaldwin Level 3
            Sure... I'm declaring a public property in the main MXML page to hold the currently highest value of a field in the array collection that's being used to populate an AdvancedDataGrid:

            [Bindable]
            public var itemTypeSortMax:Number =
            Number(itemTypeData.source[itemTypeData.source.length - 1].sort_order);

            Then, from inside an ActionScript-only component being used as an item renderer for the data grid, I'm trying to compare the current "sort_order" property against itemTypeSortMax to determine what to render. I'll paste in the whole class at the bottom of this message, but long story short, I tried (maybe incorrectly) to implement your suggestion in the set data override with:
            var currentMaxSort:Number = this.parent["itemTypeSortMax"];

            but I'm getting this error from the compiler:
            ReferenceError: Error #1069: Property itemTypeSortMax not found on mx.controls.listClasses.AdvancedListBaseContentHolder and there is no default value.

            Thanks again!

            ------------------------------------------------------------

            package components
            {

            import events.IRBtnClickE;
            import flash.events.MouseEvent;
            import mx.containers.HBox;
            import mx.controls.Image;

            public class MoveDnBtn extends HBox
            {

            private var arrowImage:Object;
            // instantiate the class and set properties
            public function MoveDnBtn()
            {
            super();
            percentWidth = 100;
            setStyle("horizontalAlign", "center");
            setStyle("verticalAlign", "middle");
            horizontalScrollPolicy = "off";
            verticalScrollPolicy = "off";
            var newImg:Image = new Image();
            newImg.source = 'images/arrow_dn.png';
            arrowImage = addChild(newImg);
            }
            // Override the set method for the data property.
            override public function set data(value:Object):void
            {
            super.data = value;
            var currentMaxSort:Number = this.parent["itemTypeSortMax"];
            if (value != null)
            {
            if (Number(value.sort_order) >= currentMaxSort)
            {
            arrowImage.alpha = .25;
            arrowImage.removeEventListener(MouseEvent.CLICK, btnClick);
            } else {
            arrowImage.alpha = 1;
            arrowImage.addEventListener(MouseEvent.CLICK, btnClick);
            }
            }
            super.invalidateDisplayList();
            }
            // trigger event and pass row data to parent component
            private function btnClick(e:MouseEvent):void
            {
            var evt:IRBtnClickE = new IRBtnClickE(super.data, 'startmovedn');
            dispatchEvent(evt);
            }

            }
            }
            • 3. Re: Parent to ItemRenderer Communication
              NateBaldwin Level 3
              Actually, what you suggested seems to be working with parentDocument instead of parent. Thanks - I think I'm good to go now.