1 Reply Latest reply on Jun 30, 2010 3:20 AM by DazFaz

    Using variables: Statement must appear within on handler

    R7AF Level 1

      I would like to use variables in my flash app. The app is quite simple, has many buttons, and on each of those buttons I have a simple script: on-rollover and on-release. For both actions I use the same value, which I want to put in a variable. The following script results in an error message: Statement must appear within on handler. When I have to declare the variable inside the on-handler, I have to declare it twice, which makes it useless as I have to enter the value twice. How can I get this working?

       

       

      country = "uk"


      on (rollOver)
      {
          gotoAndPlay(country)
      }

       

      on (release)
      {
          getURL("/"+country+"/", "_self");
      }

        • 1. Re: Using variables: Statement must appear within on handler
          DazFaz Level 1

          try:

           

          Select a frame on the timeline where your buttons live and then move the buttons handlers there:

          e.g.

           

          myButton1.onPress = onPressFunction

          myButton2.onPress = onPressFunction

          myButton3.onPress = onPressFunction

          etc.etc.

           

          myButton1.onRelease = onReleaseFunction

          myButton2.onRelease = onReleaseFunction

          myButton3.onRelease = onReleaseFunction

          etc.etc.

           

          country = "uk"

          function onPressFunction(){

               this.gotoAndPlay(country)

          }

          function onReleaseFunction(){

          {
              getURL("/"+country+"/", "_self");
          }

           

           

          If you use this approach you MUST remove the scripts from buttons themselves.

           

          I hope this helps.