6 Replies Latest reply on Apr 21, 2008 9:35 AM by rlc5611

    else encountered w/o matching if

    robin1232 Level 1
      why doesnt this code work?
      my output is:
      **Error** Scene=Scene 2, layer=Layer 1, frame=1:Line 5: Syntax error.
      else {this.gotoAndStop(1))

      **Error** Scene=Scene 2, layer=Layer 1, frame=1:Line 11: 'else' encountered without matching 'if'
      else {this.gotoAndStop(1))

      Total ActionScript Errors: 2 Reported Errors: 2

        • 1. Re: else encountered w/o matching if
          FlashTastic Level 1
          The code is a mess! if you found this code somewhere on the internet, then I suggest you start looking for better sources.

          If you wrote it yourself, you need work on your syntax. Look for some beginning actionscript tutorials (try kirupa.com, or gotoandlearn.com).

          The attached code sample is what your code should look like.

          Cheers,
          FlashTastic

          • 2. Re: else encountered w/o matching if
            rlc5611 Level 1
            In my poor understanding of boolean logic, that corrected script doesn't make any sense. The first "if" captures all events. What is the second "if" for? I think "else if" would be appropriate here otherwise the gotoAndPlay(2) will not execute for the left arrow key as the second if block will force it back to frame 1.

            And BTW, I'm not sure why you want a gotoAndPlay(2). If there is anything beyond frame 2 (i.e. frame 3 or more and implied by the "play"), it will never get there as holding the left or right arrow keys down will continue to send the clip to frame 2 because the onEnterFrame never stops running. Maybe this is the effect you want but it is a bit inefficient.

            • 3. Re: else encountered w/o matching if
              rlc5611 Level 1
              The onEnterFrame continues to run regardless of whether you are pressing a key or not. So What about placing the script in a keyframe in the timeline rather than on the clip itself. As an example, I named the clip that will move left or right "myclip".
              • 4. Re: else encountered w/o matching if
                rlc5611 Level 1
                Or if you really want to place the script on the clip itself rather than in the timeline, the equivalent script would be
                • 5. Re: else encountered w/o matching if
                  robin1232 Level 1
                  if this would help you, I wanted to create a walking animation for a game, but (offcourse) I dont want the legs to move if its not walking
                  • 6. Re: else encountered w/o matching if
                    rlc5611 Level 1
                    Well I'm not really sure how that helps me but if that is the case then you most definitely want to delete the onEnterFrame when the key is raised. That script I posted with the two key listeners is pretty much what you need. The walking animation will be controlled entirely by your movieclip that is playing while you are moving.