7 Replies Latest reply on May 26, 2010 7:42 AM by djh88ukwb

    Change States from XML

    djh88ukwb Level 1

      Hello all,

       

      I have an app, that includes a number of states.

       

      Start

      One

      Two

      Three

      Finish

       

      Im using a HTTPService to pull a state name from a XML file.  Then using the following function to determine which state is to be viewed.

       

                  private function handleState(event:ResultEvent):void
                  {
                     
                      if (event.result.state =='Finish')
                         
                          navigateToURL(new URLRequest('http://www.google.com/'), '_top')
                         
                      else 
                         
                          currentState = event.result.state;
                  }

       

      Now this all works fine, apart from oine slight problem.

       

      THe app loads in the Start state, which is fine, but then once the app has changed to the state "One", the user gets control via buttons as to which state they would like to view, using the following code - click.One="currentState='Two'".

       

      Now my only problem is the function that handles which state to view that i quoted above, is on a timer using this code

                  private function onLoad():void
                  {
                      state.send();
                      setTimeout(onLoad,1000);
                  }

       

      I used the method, so that the state is looked for every second, so once changed by the admin, the user only has to wait a second before the state changes for them.

       

       

      My problem is however that when i direct them to state "One", where they gain control over which statte via buttons, every second they are re-directed back to the state in the XML file.

       

      I need to find a work around for this.

       

      Is there another way i can go about it ?

       

      Basically i want to be able to control when users get to enter the "One" state, but i also want to be able to control when they enter the "Finish".  Whilst allowing users to be able to view states One, Two, Three etc at their own will.

        • 1. Re: Change States from XML
          djh88ukwb Level 1

          Just to mention,

           

          I have tried changing the state in the XML to one that dosent exist, and i thought this worked, it worked fine in Firefox, but IR throws an error saying that the state dosent exist.

          • 2. Re: Change States from XML
            David_F57 Level 5

            hi,

             

            So let me understand this,

             

            1. App starts (state=start)

            2. App requests a list of states

            3. Once the list is recieved state=one

            4. user can browse from one - finish

            5. User finishes and there is a url redirect

             

             

            If this is right why do we need a timer, on the http request result event can't we just set state one.

             

             

            David.

            • 3. Re: Change States from XML
              djh88ukwb Level 1

              Sorry no,

               

              The app starts in State = "Start".

               

              THen once the admin clicks a button "Live"

               

              THe app changes to State = "One"

               

              Users can then browse states from One - Three

               

              THen once the admin clicks a button "Stop"

               

              The app changes to State ="Finish".

               

               

              So the admin has control over the overall app, but the viewers can changes states freely in the middle, just not when it is live or stopped.

               

              Now i use a timer, so that it looks at the XML every second, to check whether the admin has changed the state or not,

               

              THe downfall to this is that when the user changes states in the middle, it changes back to what the admin has.

               

              I cant think of a work about, any ideas?

              • 4. Re: Change States from XML
                David_F57 Level 5

                hi,

                 

                I don't think that you can do it any other way without a timer. Unless you are using a livecycle sort of setup. Maybe after the intiial admin start signal update the timer to a bigger period of time but also do a check when the user changes tabs.

                 

                David.

                • 5. Re: Change States from XML
                  djh88ukwb Level 1

                  Would i be able to alter my PHP Script?

                   

                  At the moment it looks like this.

                  <?php
                  $images = array('Start', 'One', 'rawr', 'Finish');

                  $file = str_replace($speaker, 'assets/hold.jpg', $file);
                  $file = str_replace($images, 'Start', $file);

                  file_put_contents('change.xml', $file);
                  ?>

                   

                  Would i be able to include an option, that once the state has been changed from Start, the timer that it takes to look at the XML is changed to a real high time.  Then once the admin changes to the Finish State, the timer is brought back down to a short time so as the app looks at the XML file almost instantly?

                   

                  I.E

                   

                  State = "Start"

                  Timer = 1 second

                   

                  State = "One"

                  Timer = 1 Hour

                   

                  Admin presses Finish

                  Timer = 1 second

                  State = 1 second

                   

                   

                  Is it possible to change a timer dynamically?

                  • 6. Re: Change States from XML
                    Matt Le Fevre Level 4

                    Is it possible to change a timer dynamically?

                     

                    I imagine adding an extra attribute to the XML State object in the form of display time would be a good bet.

                     

                    for example, if your XML looked like this:

                     

                    <State>

                         <Name>Start</Name>

                         <DisplayTime>1000</DisplayTime>

                    </State>

                     

                    <State>

                         <Name>One</Name>

                          <DisplayTime>3600000</DisplayTime>

                    </State>

                     

                    <State>

                         <Name>Finish</Name>

                          <DisplayTime>3600000</DisplayTime>

                    </State>

                     

                    etc...

                     

                    add the request for a new state on the result of the previous one.

                     

                    private function onLoad():void
                    {
                        state.send();
                    }
                               
                    private function handleState(event:ResultEvent):void
                    {

                         var displayFor:int = event.result.DisplayTime;
                                  
                        if (event.result.state =='Finish')  

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

                         }      
                        else

                         {        
                             currentState = event.result.state;

                             setTimeout(onLoad, displayFor);

                         }
                    }

                     

                     

                    along those lines might work

                    • 7. Re: Change States from XML
                      djh88ukwb Level 1

                      Thank you very much Matt and David, you have both helped me yet again!

                       

                      While you are here i dont suppose you could take two minutes to look at this post could you please?

                       

                      http://forums.adobe.com/thread/628012?tstart=0