4 Replies Latest reply on May 26, 2010 1:46 AM by David_F57

    Run function on state swap

    djh88ukwb Level 1

      Hello All.

       

      I have a little program that I have encountered a problem on.

       

      Im using the following HTTPService to pull a value from a XML file.

       

              <mx:HTTPService id="state" result="handleState(event)" url="change.xml" method="POST">
                  <mx:request xmlns="">
                      <dataDumping>
                          {dataDump}
                      </dataDumping>
                  </mx:request>
              </mx:HTTPService>

       

      I am then using the following function to deal with the result.

       

                  private function handleState(event:ResultEvent):void
                  {
                      currentState = event.result.state;
                  }

       

      THis works fine, if i change the value in the XML, the application changes the state being viewed to all those currently using the app.

       

      The only problem i now face, is that i want one state to automatically re-direct to a website.

       

      For example, i have a state labeled "finish",  so when i input this into the XML file, the application automatically changes the state to the "finish" state.  This works fine,  but how do i work in the auto re-direct?

       

      I know this is the code to deal with URL links etc

       

      click="navigateToURL(new URLRequest('http://www.google.com/'), '_self')"

       

      ALthough i cant see to execute it.

       

      Any ideas?

        • 1. Re: Run function on state swap
          BhaskerChari Level 4

          Try to include this line of code navigateToURL(new URLRequest('http://www.google.com/'), '_self') in the function or block where you can identify the state change in your app..instead of including it in the click event..so that as the state changes it will redirect automatically to the website.

           

          If this post answers your question or helps, please kindly mark it as such.

           

          Thanks,

          Bhasker Chari

          1 person found this helpful
          • 2. Re: Run function on state swap
            David_F57 Level 5

            hi,

             

            Maybe I miss what you are doing but wouldn't it be something like this...

             

                        private function handleState(event:ResultEvent):void
                        {

                              if (event.result.state =='finished')

                                    navigateToURL(new URLRequest('http://www.google.com/'), '_self')

                              else  

                                  currentState = event.result.state;
                        }

             

             

            David

            • 3. Re: Run function on state swap
              djh88ukwb Level 1

              Im sorry i think i didnt explain myself well enough.

               

              The state is changed using the following function

               

                          private function handleState(event:ResultEvent):void
                         {
                              currentState = event.result.state;
                          }

               

              So if i was to add the navigate url code within this function, then everytime i change states it will go to the new URL, not just on the "Finish" state.

               

              I assume i need some sort of IF statement.

               

              i.e.

               

              If state = "Finish" then navigate, else dont.

               

              Although im not sure how to code this . . .

              • 4. Re: Run function on state swap
                djh88ukwb Level 1

                Problem solved, thanks !