5 Replies Latest reply on Nov 14, 2010 9:15 AM by BennyB23

    Updating/Changing ViewState properties

    BennyB23

      I'm having trouble figuring out how to update ViewState-based changes. For example, I'd like to set a spark button component's enabled state to false for a particular viewState in the main application. I've tried numerous approaches to handling the state changes and setting properties explicitly, but I'm clearly not doing it properly, because none of the event handling, aside from the creationComplete event, do anything. If anybody has some suggestions please let me know.

       

      Thanks~Benny

        • 1. Re: Updating/Changing ViewState properties
          John Hall Level 4

          Any chance you could share a simple example of your approach? Seems doable with a conditional.

          • 2. Re: Updating/Changing ViewState properties
            BennyB23 Level 1

            Hey John,

             

            Here's an example:

             

            <fx:Script>

            <![CDATA[

            //mediaPlayer:VideoPlayer...

             

            import mx.events.FlexEvent;

            import mx.events.StateChangeEvent;

             

            protected function application1_creationCompleteHandler(event:FlexEvent):void

            {

                 mediaPlayer.fullScreenButton.enabled = false;

                 mediaPlayer.fullScreenButton.addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE, stateChangeHandler);

            }

             

            protected function stateChangeHandler(event:StateChangeEvent):void

            {

                 if (event.newState == "videoMenu")

                 {

                      mediaPlayer.fullScreenButton.enabled = true;

                 }

                 else

                 {

                      mediaPlayer.fullScreenButton.enabled = false;

                 }

            }

            ]]>

            </fx:Script>

             

            <s:states>

            <s:State name="audioMenu"/>

            <s:State name="videoMenu"/>

            </s:states>

            <!-- ============================ -->

             

            Let me know if you have any ideas...

             

            Thanks~B

            • 3. Re: Updating/Changing ViewState properties
              BennyB23 Level 1

              I just realized something sort of foolish; I'm not actually calling the stateChange event... I'll explain.

              I have a ViewStack component with two NavigatorContent containers and in my code I have the following:

               

              <ViewStack

              selectedIndex.audioMenu="0"

              selectedIndex.videoMenu="1">

               

              ... So I guess I should be listening for the childIndexChange (I think that's what it is). That said, do you have any suggestions as to what would be reasonable way of calling the stateChange event? I'm using a TabBar component as the dataProvider for the ViewStack.

               

              Thanks~B

              • 4. Re: Updating/Changing ViewState properties
                BennyB23 Level 1

                This has been quite the roundabout post on my part, but I can't say it's the first and I wouldn't put money on it being the last...

                 

                At any rate, I can't say that I've answered my own question, but the code that I came up with to achieve the desired result, as described in my previous post looked like this:

                 

                protected function playListVS_changeHandler(event:IndexChangedEvent):void

                {

                     if (event.newIndex == 1)

                     {

                          mediaPlayer.fullScreenButton.enabled = true;

                     }

                     else

                     {

                          mediaPlayer.fullScreenButton.enabled = false;

                     }

                }

                 

                I'm still not sure how to change the application's ViewState in reaction to another event, so if someone wants to explain that I'd appreciate it.

                 

                Thanks~B

                • 5. Re: Updating/Changing ViewState properties
                  BennyB23 Level 1

                  Wow, what an embarrassing post...

                  protected function playListVS_changeHandler(event:IndexChangedEvent):void

                  {

                       if (event.newIndex == 1)

                       {

                            mediaPlayer.fullScreenButton.enabled = true;

                            currentState = "videoMenu";

                       }

                       else

                       {

                            mediaPlayer.fullScreenButton.enabled = false;

                            currentState = "audioMenu";

                       }

                  }

                  Note to self: don't append question without prior review of documentation, don't eat the yellow snow, find peace in lack of expertise on the path to the opposite...

                   

                  ~B