4 Replies Latest reply on Aug 9, 2011 3:34 PM by John Hall

    Understanding variable scope in spark itemRenderer

    John Hall Level 4

      I've tried many things, including overriding get and set of data going into a custom itemRenderer but I'm missing a basic principle I think. So, assuming I inject the data into a custom itemRenderer, a debug shows it's getting the data, data labels are all fine etc, I want to then click on the itemRenderer and access the data (provider). However, if I debug the AS3 inside the itemRenderer, the data variable I set when the itemRenderer was created is obviously out of scope. Can someone point me to a good explanation of the vagaries of object scope inside spark itemRenderers.

        • 1. Re: Understanding variable scope in spark itemRenderer
          GordonSmith Level 4

          As far as I know, you're not supposed to be setting the 'data' of an item renderer yourself. It is set by the component (e.g., spark.components.List) that creates the item renderer, and it gets set to the element in the dataProvider that the renderer is created to render. So whatever you're setting it to is probably getting clobbered by what the component wants to set it to.


          Gordon Smith

          Adobe Flex SDK Team

          • 2. Re: Understanding variable scope in spark itemRenderer
            John Hall Level 4

            Thanks Gordon. I'm probably not phrasing it well. Nor am I approaching it well, so I'll ask for advice on the actual issue. I have a calendar. I have categories of appointments associated with these calendar appointments and those combination of categories are determined by checkboxes I check in another component using an itemRenderer inside that component. So if I have one checkbox marked when I dispatch a createNewAppointment, one type of appointment will be created. And if two are checked, another type of appointment will be created. The appointment shows up graphically on the calendar using itemRenderers for the calendar. That all works fine.

             

            Now I'd like to go the other way. When I click on a calendar appointment itemRenderer, I'd like update the checkboxes in the other list to reflect the appointment that now has the focus. It's pretty straight forward getting and setting the properties of the event like description, time etc because they are placed into textboxes and have named targets, but I'm having trouble finding the best approach to update the itemRenderers in the first list to reflect the type of appointment that now has the focus. So I'm open to suggestions to how I programmatically reflect the attributes of the calendar appointment I click by getting the checkboxes to reflect the number that was checked when I created the event.

            • 3. Re: Understanding variable scope in spark itemRenderer
              Amy Blankenship Level 4

              If the event you dispatch from the renderer is bubbling, you can listen to it any place on the display list that is above the renderer on the display list.  If you assume that there is also some place above the renderer that knows about the check boxes (or some variable the check boxes are bound to), then in the event handler for that event you can set the check box/variable values.

               

              It's difficult to get more specific than that without  some code from you .

              • 4. Re: Understanding variable scope in spark itemRenderer
                John Hall Level 4

                Thanks, Amy. I'm working away understanding scope inside itemRenderers with selectedItems (a Vector) changing and updating the dataProvider for the selectedItems. In other words, I appreciate your help and if I'm still stuck tomorrow I'll try to share a simple code example.