6 Replies Latest reply on Nov 13, 2008 8:05 AM by rmorgan

    Undefined State

    rmorgan Level 1
      I am trying to refer to States dynamically and keep getting an error telling me that the state is undefined.
      <mx:RadioButtonGroup id="affiliation" />
      <mx:Repeater id="rp" dataProvider="{acArtists}">
      <mx:RadioButton label="{rp.currentItem.grouptype}" groupName="affiliation" click="currentState='{rp.currentItem.grouptype}'"/>
      </mx:Repeater>

      How come it is defined for the label but not for current state?

      Below is the error.
      ArgumentError: Undefined state '{rp.currentItem.grouptype}'.
      at mx.core::UIComponent/getState()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\core\UI Component.as:7170]
      at mx.core::UIComponent/findCommonBaseState()[E:\dev\3.1.0\frameworks\projects\framework\src \mx\core\UIComponent.as:7190]
      at mx.core::UIComponent/commitCurrentState()[E:\dev\3.1.0\frameworks\projects\framework\src\ mx\core\UIComponent.as:7089]
      at mx.core::UIComponent/setCurrentState()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:7053]
      at mx.core::UIComponent/set currentState()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\core\UIComponent.as:4339 ]
      at myfirstflex/___myfirstflex_RadioButton17_click()[N:\myfirstflex\src\myfirstflex.mxml:110]
        • 1. Re: Undefined State
          ericbelair Level 1
          This is why I stay away from Repeaters. I had similar problems, and eventually ended up using a List component, displaying the items in item Renderers, and handling all logic in the item renderer.
          • 2. Re: Undefined State
            rmorgan Level 1
            ok....???
            • 3. Re: Undefined State
              Level 7

              "rmorgan" <webforumsuser@macromedia.com> wrote in message
              news:gfa3dd$10l$1@forums.macromedia.com...
              >I am trying to refer to States dynamically and keep getting an error
              >telling me
              > that the state is undefined.
              > <mx:RadioButtonGroup id="affiliation" />
              > <mx:Repeater id="rp" dataProvider="{acArtists}">
              > <mx:RadioButton label="{rp.currentItem.grouptype}" groupName="affiliation"
              > click="currentState='{rp.currentItem.grouptype}'"/>
              > </mx:Repeater>
              >
              > How come it is defined for the label but not for current state?
              >
              > Below is the error.
              > ArgumentError: Undefined state '{rp.currentItem.grouptype}'.

              By the time you click, the repeater is done repeating and its currentItem
              property will be null. Try

              <mx:RadioButtonGroup id="affiliation" />
              <mx:Repeater id="rp" dataProvider="{acArtists}">
              <mx:RadioButton label="{rp.currentItem.grouptype}" groupName="affiliation"
              data="{rp.currentItem}"
              id="rb" click="changeState(event)">
              </mx:Repeater>

              and then

              private function changeState(e:Event) {
              var btn:RadioButton = e.currentTarget as RadioButton;
              currentState=btn.data.grouptype;
              }

              HTH;

              Amy


              • 4. Re: Undefined State
                rmorgan Level 1
                Thanks, looks like it will work but it was giving a warning but I think I worked it out. In your example:

                private function changeState(e:Event) {
                var btn:RadioButton = e.currentTarget as RadioButton;
                currentState=btn.data.grouptype;
                }

                The warning was: 1008: return value for function 'changeState' has no type declaration.

                So, I changed it to:
                private function changeState(e:Event):void{
                var btn:RadioButton = e.currentTarget as RadioButton;
                currentState=btn.data.grouptype;
                }

                I added the :void directive and it took the warning away, was this the proper way of fixing the warning?
                • 5. Re: Undefined State
                  Level 7

                  "rmorgan" <webforumsuser@macromedia.com> wrote in message
                  news:gfcir5$ebf$1@forums.macromedia.com...
                  > Thanks, looks like it will work but it was giving a warning but I think I
                  > worked it out. In your example:
                  >
                  > private function changeState(e:Event) {
                  > var btn:RadioButton = e.currentTarget as RadioButton;
                  > currentState=btn.data.grouptype;
                  > }
                  >
                  > The warning was: 1008: return value for function 'changeState' has no type
                  > declaration.
                  >
                  > So, I changed it to:
                  > private function changeState(e:Event):void{
                  > var btn:RadioButton = e.currentTarget as RadioButton;
                  > currentState=btn.data.grouptype;
                  > }
                  >
                  > I added the :void directive and it took the warning away, was this the
                  > proper
                  > way of fixing the warning?
                  >

                  Yes. That's a mistake I make several times a day. Luckily, Flex is there
                  to point it out ;-)


                  • 6. Undefined State
                    rmorgan Level 1
                    Thanks. Along the lines of where I am going with this previously, if I want to refer to the actual states dynamically, what would I make the name of the state so that I can create the states dynamically? I tried searching but searching for criteria for "dynamic states" does not return anything useful.

                    <mx:state name="SOME DYNAMIC NAME">