5 Replies Latest reply on Oct 6, 2011 3:56 AM by Filmzaddict

    setCurrentState() override inside itemRenderer

    Filmzaddict Level 1

      Well, as adviced, i divided separated the itemRenderer into a few VGroups, each with an includeIn="stateName" attribute, also, there are a couple of states defined (im not using standard names for states). In the data property of the renderer i use a field from the supplied object to decide which state to use, and i set the state using setCurrentState("stateName", false). At runtime this throws an error as soon as i reference a component from a particular state (which should have been set) because all the references are null, so i googled and learned that i need some sort of override to the setCurrentState() method, and perhaps also to the getCurrentState method. Not sure what im supposed to put into the overrides.

       

      Any ideas?

       

      Thanks

        • 1. Re: setCurrentState() override inside itemRenderer
          Flex harUI Adobe Employee

          In 4.5 there is a getCurrentRendererState() method.

          1 person found this helpful
          • 2. Re: setCurrentState() override inside itemRenderer
            Filmzaddict Level 1

            Okay heres what i did:

             

            protected override function getCurrentRendererState():String

                                          {

                                                    trace(super.getCurrentRendererState());

                                                    switch (_Parameter(data).Type)

                                                    {

                                                              case ParameterTypeEnum.ENTRY_SELECTION:

                                                                        return "selectionState";

                                                              default:

                                                                        return "";

                                                    }

                                          }

             

            The trace above returns "normal" which is by the book. I also have a normal state defined in states of the custom renderer, but nothing is included inside it The program flow actually hits return "selectionState" statement.

             

            i would use the getCurrentRendererState inside the overriden data property like this: this.currentState = getCurrentRendererState();

             

            Unfortunately when data is set is still throws the null reference errors on component references because the state was still not set correctly.

            • 3. Re: setCurrentState() override inside itemRenderer
              Filmzaddict Level 1

              does this.currentState or setCurrentState work async? Because if i trace the state i see its actually the correct state, but all the references to states components are null. I used includeIn="stateName" for all components. Then i added itemCreationPolicy="immediate" and it works, but i wonder if all the components are created immedietely (even if they arent in the state that is active at the moment; if thats true, i kind of loose the point of having states in this case).

              • 4. Re: setCurrentState() override inside itemRenderer
                Filmzaddict Level 1

                Hmm, its not a good solution, because everytime data property is set, all the bindings fire off, even those in inactive states, because the components have been initialized, but since the objects type isnt the right one, casting fails, grrrr :>

                • 5. Re: setCurrentState() override inside itemRenderer
                  Filmzaddict Level 1

                  Forget it, im going with itemRendererFunction