4 Replies Latest reply: Jun 22, 2007 1:15 AM by Paradigm RSS

    Flag or Variable Required for Navigation

    Paradigm Community Member
      I need some help with (hopefully) a small addition to my actionscript.

      I have a touchscreen in our reception, the Flash presentation on here currently has a set-up screen (1st Scene, named "Input") with a text input box, the results of which get displayed on the next Scene which is called "Welcome". When a visitor touches the screen the presentation jumps to another Scene called "Main". On the timeline of "Main" there's a counter set up to detect whether the screen has been touched in the last 5 mins, if not the presentation jumps back to "Welcome", waiting for the next touch.

      I'd like to change the "Input" Scene and have two options for the person setting up the presentation (someone has to do this every morning). I'd like two welcome screens, one with a static standard greeting "Welcome to Gillingham" for example. The other welcome screen would be the same as described above with the input text box.

      The trouble is once the presentation jumps into the "Main" Scene, there's no way to indicate from WHICH welcome screen it started from - the static text or the input text. So what I think I need is a simple variable or "flag" somewhere in the timer actionscript to indicate that if the flag is on go to "Welcome_1" and if not go to "Welcome_2" after the 5mins of inactivity.

      Here's my timer script set-up on Frame 1 of the "Welcome" Scene:

      DisplayedCompany.text=_root.CompanyName;
      var timeoutID = setInterval(timedOut, 180000);

      function timedOut () {
      clearInterval(timeoutID);
      gotoAndStop("Welcome",1);
      }

      onMouseMove = function(){
      clearInterval(timeoutID);
      timeoutID = setInterval(timedOut, 180000);
      }


      And here's my timer script on Frame 1 of my "Main" Scene - looking for activity within 5 mins:

      if(!timeoutID){
      var timeoutID = setInterval(timedOut, 180000);
      }

      function timedOut () {
      clearInterval(timeoutID);
      _root.gotoAndStop("Welcome_1"); // be sure to label this frame on Welcome's frame 1.
      }

      onMouseMove = function(){
      clearInterval(timeoutID);
      timeoutID = setInterval(timedOut, 180000);
      }

      I'm not a programmer, all of the above script has been suggested by other forum users, so a very simple explanation on what I suspect is a very simple addition would be much appreciated.
        • 1. Re: Flag or Variable Required for Navigation
          MotionMaker Community Member


          Set a variable to indicate the welcome screen such as welcomeId.
          var welcomeId:Number; // On first frame before all others

          welcomeId = 1; // On first frame for the main scene

          welcomeId = 2; // On first frame for the input scene.

          In the timeOut()
          if (welcomeId == 1)
          {
          _root.gotoAndStop("Welcome_Main"); // Supply correct scene names
          }
          else
          {
          _root.gotoAndStop("Welcome_Input");// Supply correct scene names
          }
          • 2. Flag or Variable Required for Navigation
            Paradigm Community Member
            Hi Lon, thanks for the suggestion. If I've followed your code right (and Flash had a problem with the syntax when I ran the "check syntax") the timer is now not responding. Just to recap, Frame 1 of "Welcome" Scene contains the static text message and is labelled "Welcome_1", Frame 2 contains the dynamic text message (from the "Input" Scene) and is labelled "Welcome_2".
            Here's what I added:

            Frame 1 of the first Scene "Input"

            var welcomeId:Number;
            fscommand("allowscale", "true");
            fscommand("resize", "false");
            fscommand("showmenu", "false");
            fscommand("fullscreen", "true");
            stop();


            Frame 1 of the "Welcome" Scene:
            welcomeId=1;
            stop();

            Frame 2 of the "Welcome" Scene:
            welcomeId=2;
            stop();

            The timer script on the timeline in the "Main" Scene now looks like this:

            if(!timeoutID){
            var timeoutID = setInterval(timedOut, 180000);
            }

            function timedOut ()
            {clearInterval(timeoutID);}
            if(welcomeId==1)
            {
            _root.gotoAndStop(Welcome, "Welcome_2");
            }
            else

            _root.gotoAndStop(Welcome, "Welcome_1");
            onMouseMove = function(){
            clearInterval(timeoutID);
            timeoutID = setInterval(timedOut, 180000);}

            I obviously haven't implemented correctly, what have I done wrong?

            For your info, there is more script on Frame 1 of "Welcome" on a different layer, it's more of the timer script:

            DisplayedCompany.text=_root.CompanyName;
            var timeoutID = setInterval(timedOut, 180000);

            function timedOut () {
            clearInterval(timeoutID);
            gotoAndStop("Welcome",1);
            }

            onMouseMove = function(){
            clearInterval(timeoutID);
            timeoutID = setInterval(timedOut, 180000);
            }
            • 3. Re: Flag or Variable Required for Navigation
              MotionMaker Community Member
              If you have a syntax error, the code is not going to work.
              Without providing the error message, it is not going to be easy to dig it out, but using the rule of looking at code changes first is the error a missing close curly brace here

              else

              _root.gotoAndStop(Welcome, "Welcome_1");
              }

              Not sure what code goes before the } but {} are a block of code. There is a line that precedes {} such as if or else or function that defines when the block is played.



              A possible runtime logic error may occur if the welcomeId variable is not maintained. So I am not sure if you are returning to the "Input" scene. If you are then that variable value gets destroyed.

              You need to declare
              var welcomeId:Number;
              once and I am not sure where that would be in your code but it needs to be on a frame that is played only one time before the other frames are played that use welcomeId.
              • 4. Re: Flag or Variable Required for Navigation
                Paradigm Community Member
                Thanks Lon.

                Although initially there was a syntax error, I meant to say I corrected this before re-publishing, but I still sem to have lost the timer functionality, the presentation now DOESN'T return to the "Welcome" Scene.

                I note your comment on returning to the frame with the variable declaration, but this is on Frame 1 of the "Input" Scene, which once the action moves to the "Welcome" Scene isn't revisited. Let me recap the Scene layout with regards to your code, Scenes listed in order:

                "Input" Scene:
                Frame 1:
                var welcomeId:Number;

                There are two butons here, one for the static text welcome:
                on (release) {
                gotoAndPlay("Welcome","Welcome_2");
                }

                and one to go to the next Frame which is where you input your text for the "customised" text welcome:

                on (release) {
                gotoAndPlay("custom_screen");
                }

                from here you then click a "begin" button which takes you to Frame 1 of the "Welcome" Scene:

                on (release) {
                gotoAndPlay("Welcome","Welcome_1");
                }

                "Welcome" Scene:
                Frame 1 (labelled "Welcome_1"):
                welcomeId=1;
                stop();

                On another layer I have more script to display the dynamic text and to check the timer:

                DisplayedCompany.text=_root.CompanyName;
                var timeoutID = setInterval(timedOut, 180000);

                function timedOut () {
                clearInterval(timeoutID);
                gotoAndStop("Welcome","Welcome_1");
                }

                onMouseMove = function(){
                clearInterval(timeoutID);
                timeoutID = setInterval(timedOut, 180000);
                }

                Frame 2 here is identical to Frame 1, except it's labelled "Welcome_2" and your code for the variable:

                welcomeId=2;
                stop();

                This is displaying the static text welcome message. The other script here on another layer, again, for the timer:

                var timeoutID = setInterval(timedOut, 180000);
                function timedOut() {
                clearInterval(timeoutID);
                gotoAndStop("Welcome","Welcome_2");
                }
                onMouseMove = function () {
                clearInterval(timeoutID);
                timeoutID = setInterval(timedOut, 180000);
                };

                "Main" Scene:
                This Scene is the main presentation with all of the information for the user. The timer has been set up to watch for 5 mins of inactivity before returning back to the "Welcome" Scene. I was hoping your script would determine WHICH welcome text screen is displayed at this point, either Frame 1 of "Welcome" (the dynamic text) or Frame 2 of "Welcome" (the static text). Here's all of the script inc the timer stuff and your variable stuff, all on Frame 1:

                if(!timeoutID){
                var timeoutID = setInterval(timedOut, 180000);
                }

                function timedOut ()
                {clearInterval(timeoutID);}
                if(welcomeId=2)
                {
                _root.gotoAndStop("Welcome","Welcome_2");
                }
                else
                {
                _root.gotoAndStop("Welcome","Welcome_1");
                }
                onMouseMove = function(){
                clearInterval(timeoutID);
                timeoutID = setInterval(timedOut, 180000);}

                The syntax here is all correct, I changed "if(welcomeId==1)" to "if(welcomeId=2)" - but this made no difference I could determine as without the timer to redirect the action back to "Welcome" I don't know where it'll end up.

                I'm sure there's a very simple "tweak" to be made, but I can't fathom it. Any help would be appreciated.

                Best regards

                Paul.