3 Replies Latest reply on Jan 25, 2007 7:31 AM by MotionMaker

    Button will still not work!

    aspidistra Level 1
      In my previous post I was using a button component to perform a calculation when clicked upon using.....on(click) {
      with(_parent){ however I need to use a designed button and this has to perform a calculation and go to another frame....so when I tried this it will now not work.

      Previously in the button component version I had the main actionscript in the first frame and the on (click) actionscript directly on the button component....BUT when I use a regular 4 state button with actionscript in the main script now this will not work.

      BEFORE (which worked - actionscript on button component)

      //Calculates total price.
      on(click) {
      with(_parent){
      priceTotal_txt.text = Number (price1_txt.text) + Number (price2_txt.text) + Number (price3_txt.text);
      }
      }


      SCRIPT WHICH WILL NOT WORK - DESIGNED BUTTON,ACTIONSCRIPT IN FRAME 1 :

      //Calculates total price.
      two_btn.onRelease = function() {
      priceTotal_txt.text = Number (price1_txt.text) + Number (price2_txt.text) + Number (price3_txt.text);
      };

      Can anyone explain why this will not work?

      thanks
      E

      ERROR IS :
      **Error** Symbol=button, layer=Layer 1, frame=1:Line 2: Invalid mouse event specified.
      on(click) {

      **Error** Symbol=button, layer=Layer 1, frame=1:Line 3: Statement must appear within on handler
      with(_parent){

      **Error** Symbol=button, layer=Layer 1, frame=1:Line 6: Unexpected '}' encountered
      }

      Total ActionScript Errors: 3 Reported Errors: 3
        • 1. Re: Button will still not work!
          MotionMaker Level 1
          The error occurs when you place the BEFORE script and the "SCRIPT WHICH WILL NOT WORK" code on the instance of a Button Symbol.

          If you add actions to an instance of a Button Symbol then you need on(event name){
          as the first line and } as the last line. See
          on handler in Flash documentation.
          You should also study Using on and onClipEvent with event handler methods in the documentation and in particular the "To use an on handler and onPress event handler:" topic.
          • 2. Re: Button will still not work!
            aspidistra Level 1
            Thanks, I have it working now.

            I assume as this article says it is better to have all the actionscript on one frame script, rather than some separately on a button or movie clip.

            Emma
            • 3. Re: Button will still not work!
              MotionMaker Level 1
              Great to hear.

              "I assume as this article says it is better to have all the actionscript on one frame script, rather than some separately on a button or movie clip."

              I think that is a preference. To find code attached to buttons and MovieClips, you can use the Window->Movie Explorer and unselect all but the Actions button to locate actions in a Flash movie. You also can use the Script Navigator panel in the Actions window introduced starting I believe with MX 2004 version.

              For coders the idea of having code "hidden behind" GUI objects is generally not as efficient and easy to maintain. Just adds to many keystrokes and mouse clicks as well as being difficult to remember where stuff is. So you can place all your code for a swf or a MovieClip on the first frame as a starting point. As you learn more you can place code in external AS files and link them in with #include or if you are OOP programming using import.