2 Replies Latest reply on May 17, 2007 12:10 PM by KreepyKen

    Variables & if / else if statements

    KreepyKen Level 1
      This is probably a basic concept, and I've been able to get some of it, but I just can't seem to seal the deal and make this work. I'm pretty clueless with anything that resembles programming, so I need a little help.

      I have a flash file where the main timeline has stops on every frame. Each frame contains a movie clip, each movie clip contains three smaller, nested movie clips. These nested movie clips contain four buttons in various places. The overall effect is one of an interactive slide show where the user is presented with a giant list on frame 1 of fhe main timeline. Say s/he clicks the first item in the list, s/he then jumps to frame 2 in main timeline and stops. Movie clip plays: first nested movie clip tweens into view and contains three of the four buttons. When the user clicks one of the buttons, here's what I want to happen:

      1. Button sets variable _global.xxx to some value
      2. Button tells parent movie clip to play
      3. Parent movie clip plays: makes nested movie clip tween off screen
      4. Parent movie clip hits a script (attached to frame in script layer) that tells it to jump to a certain frame (using labels, not frame numbers) based on the value of the variable set by the button
      5. Parent movie clip jumps to that frame and another nested movie clip tweens onto screen

      I can assign the variable okay with the buttons, but I can't seem to get the if/else script correct in the parent timeline. Steps 1, 2, and 3 are good. But I can't get the parent movie clip to make the jump to the labeled frame.

      It seems that maybe I need a function and I perused the internet and this forum for ideas, but can't seem to successfully adapt anything.

      Here is the script I have. It is attached to a frame in a layer I have reserved for scripts in the parent movie clip:

      quote:


      if (_global.xxx = "gui") {
      this.gotoAndPlay("accugui");
      }
      else if (_global.xxx = "cli") {
      this.gotoAndPlay("accucli");
      }
      else if (_global.xxx = "cvs") {
      this.gotoAndPlay("cvs");
      }
      else if (_global.xxx = "ret") {
      this.gotoAndPlay("return");
      }
      else {
      stop();
      }


      Should this be contained in something else, like a function? I tried creating a function, and I had some different effect, but still not the right one...and I suspect the function wasn't nearly complete. I would appreciate any ideas.

      Thank you very much.
        • 1. Re: Variables & if / else if statements
          Level 7
          Count Techula,

          > When the user clicks one of the buttons, here's what
          > I want to happen:
          > 1. Button sets variable xxx to some value

          To have a button respond to user input, you'll need to write an event
          handler. Give your button an instance name in the Property inspector. That
          instance name is what allows ActionScript to "communicate" directly with the
          button in question. For sake of discussion, let's say you choose the
          instance name myButton.

          myButton.onRelease = function():Void {
          // instructions here define what happens
          // when the user clicks this button,
          // then lets go
          }

          > 2. Button tells parent movie clip to play

          If the movie clip in question is the immediate parent of this button,
          that could go like this:

          myButton.onRelease = function():Void {
          this._parent.play();
          }

          > 3. Parent movie clip plays: makes nested movie clip tween off screen

          That presumably occurs because of tweens in the parent movie clip's
          timelines, right?

          > 4. Parent movie clip hits a script (attached to frame in
          > script layer) that tells it to jump to a certain frame (using
          > labels, not frame numbers) based on the value of the
          > variable set by the button

          Okay. This depends entirely on the script, but it looks like you've
          provided that below.

          > 5. Parent movie clip jumps to that frame and another nested movie
          > clip tweens onto screen

          Again, presumably determined by tweens in this parent movie clip's
          timeline.

          > Steps 1, 2, and 3 are good. But I can't get the parent movie
          > clip to make the jump to the labeled frame.

          Aha. Well, you're going to kick yourself. Ready?

          > Here is the script I have. It is attached to a frame in a layer I have
          > reserved for scripts in the parent movie clip:

          > if (_global.xxx = "gui") {

          Right here, you're using the assignment operator (=), rather than the
          comparison operator (==). What's happening in that if() statement is two
          things: from inside out ... a) the _global.xxx property is being *set* to
          the string "gui", and b) the if() statement determines is that assignment
          occured. It will always be a successful assignment, because _global.xxx =
          "gui" is about as simple as it gets. That expression will set the value of
          xxx in the _global object, and therefore the if() statement will always
          interpret that as true.

          Wat you want is this:

          if (_global.xxx == "gui") {


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Variables & if / else if statements
            KreepyKen Level 1
            David,

            Thank you so much for the lightning-fast response. The double equals did the trick, and your explanation of the difference between single & double made a lot of sense. One thing I left out in the interest of brevity was that the animation did keep jumping to the final place listed in the sequence of "if statements"...as if the final value was retained by the variable. It made no sense to me before, but it makes perfect sense now that I know all those if statements kept assigning the variable as they went along.

            I really appreciate your time & effort in helping me out with this.