4 Replies Latest reply on Feb 23, 2009 11:07 PM by ntsiii

    Using a canvas as an itemrenderer - how to access the datafield?

    Lvw2000
      Yes... another ItemRenderer related question...

      So I have this advancedDataGrid of which I dynamically generate the columns in actionscript. Each of these columns get their own datafield.

      This code works well, since all the data displays nicely where I want it to be.

      However, in the columns there are numbers from like 0 to 10, these are put there by the default itemrenderer by using the datafield. Instead of just displaying these numbers, I'd like to use a canvas as an itemrenderer to draw something in the box based on the value of the number. So all I need to access in my Canvas is the value that is parsed by the datafield.

      I thought to do so by overriding public function set data(value:Object):void

      But what does value contain? I tried doing something with it but I keep getting errors. Does value just contain the entire dataProvider? Or is there a way to acces just the number that would be put on that position in the grid if I wouldn't be using a custom itemrenderer at all?

      I've searched tons of blogs but haven't found the exact answer to my question yet.

      Many thanks in advance.
        • 1. Re: Using a canvas as an itemrenderer - how to access the datafield?
          run,ryan! Level 3
          you can define a customized object class extending displayobject and add that object to your canvas
          as to accessing the value, i think following code will work
          yourObj = yourCanvas.getChildAt(index);
          yourVal = yourObj.yourProp;
          //yourProp is defined in your class and storing the value from your data source
          • 2. Re: Using a canvas as an itemrenderer - how to access the datafield?
            Level 7

            "Lvw2000" <webforumsuser@macromedia.com> wrote in message
            news:gnucks$8kh$1@forums.macromedia.com...
            > Yes... another ItemRenderer related question...
            >
            > So I have this advancedDataGrid of which I dynamically generate the
            > columns in
            > actionscript. Each of these columns get their own datafield.
            >
            > This code works well, since all the data displays nicely where I want it
            > to be.
            >
            > However, in the columns there are numbers from like 0 to 10, these are put
            > there by the default itemrenderer by using the datafield. Instead of just
            > displaying these numbers, I'd like to use a canvas as an itemrenderer to
            > draw
            > something in the box based on the value of the number. So all I need to
            > access
            > in my Canvas is the value that is parsed by the datafield.
            >
            > I thought to do so by overriding public function set
            > data(value:Object):void
            >
            > But what does value contain?

            It contains the information needed for the entire row. Just put a break
            point in the code in your override function and then run the application in
            debug mode. Use the variables window to inspect the value.

            > I tried doing something with it but I keep
            > getting errors.

            Are the errors related to the value or are they related to something else,
            such as trying to set properties on subcomponents that have not been
            instatiated yet.

            > Does value just contain the entire dataProvider? Or is there a
            > way to acces just the number that would be put on that position in the
            > grid if
            > I wouldn't be using a custom itemrenderer at all?

            Look at implementing IDropInListItemRenderer and then look at
            listData.label.

            HTH;

            Amy


            • 3. Re: Using a canvas as an itemrenderer - how to access the datafield?
              Lvw2000 Level 1
              Thanks a lot for your help people. My first approach was with a DropInListItemRenderer, but that appaers to be mostly usefull if you need to know the state of the entire grid, which isn't the case here.

              I've come up with another possibility myself. Instead of overriding set data, I override updatedisplaylist. Then I can find the piece of info I need in may dataprovider based on a property I've set at the time I add the renderer to the row. So basically I've found a way to do what I want, but it's very buggy atm. Collapsing and expanding rows from the filetree at the left (the dataprovider is hierarchicaldata) renders to a lot of undesired effects with data moving to wrong rows and all...

              But it's nearly impossible to explain what exactly happens on this forums.

              Lots of thanks to you and happy coding! :)
              • 4. Re: Using a canvas as an itemrenderer - how to access the datafield?
                ntsiii Level 3
                If the visual characteristics of your ItemRenderer depend on the values in the dataProvider items (this is usually the case, and is why they are called 'item renderers'), the the set data() and "commitProperties" functions are critical. You must set the visual state when the data changes (when commitProperties is called, actually). "...data moving to wrong rows ..." sounds like you are not doing that. Read up on renderer "recycling".

                The "value" argument in set data() is a reference to the dataProvider item for the row that the renderer is on. How you access the data in that item depends on what the item object data type is (Object, XML, custom VO,...)

                Unless you are an expert, do not try to build an itemRenderer from scratch. Instead, find one and modify it.