Button & movie clips problem

I know the answer to this is probably staring right in my face, but I’m having a heckuva time getting this to work correctly in MX.

Let’s say you have a button instance named MyButton. When pressed, you’d like two things to happen one-after-another: a movieclip somewhere else on the page to play out to completion and then stop, followed immediately by the playing of a separate second clip.

What’s messing me up is that I have five buttons total that all need to do this, each playing a different second clip. On top of that, they all need to be able to play the same first clip, but only when it hasn’t already been played (meaning the first clip is only played ONCE – when the user first presses any one of the five buttons).

Basically I’m trying to pin down the syntax to doing this:

When pressed, check to see if movie clip 1 has played out. If so, play movie clip 2. If not, play clip 1 to completion, then play clip 2.

Jeez, I am SO confused. Help!

I’d go with two strategies.

  1. To get the first clip to play the proper second clip, set a variable when the button is clicked. At the end of the first clip, do a check for the variable and play the proper clip. E.g.

// on button 1
on (release) {
  var location = "clip1";
  gotoAndPlay("_firstClip");
} // end on (release)

// on button 2
on (release) {
  var location = "clip2";
  gotoAndPlay("_firstClip");
} // end on (release)

// etc.

Then at the end of _firstClip, do something like this:


// check for "location"
if (location == "clip1") {
  gotoAndPlay("_secondClip1");
} else if (location == "clip2") {
  gotoAndPlay("_secondClip2");
} else if (etc.) {
  // etc.
} // end "if (location == ... )"

  1. To be sure that the first clip is only played once, set a flag when the button is clicked and then only play _firstClip if that flag has not been set.

// set the array containing the buttonsClicked flags //

var buttonsClicked = new Array();
buttonsClicked[0] = false;
buttonsClicked[1] = false;
etc.

// modife the code on the buttons as so //

// on button 1
on (release) {
  if (buttonsClicked[0] == false) { // button hasn't been flagged
    // set the location variable and go to the first clip    
    var location = "clip1";
    gotoAndPlay("_firstClip"); 
  } else { // button has been flagged
    // go directly to the second clip
    gotoAndPlay("_secondClip1"); 
  }  // end "if buttonsClicked == false"
  // the button has been clicked, so flag the button
  buttonsClicked[0] == true; 
} // end on (release)

// on button 2
on (release) {
  if (buttonsClicked[1] == false) { // button hasn't been flagged
    // set the location and go to the first clip    
    var location = "clip2";
    gotoAndPlay("_firstClip"); 
  } else { // button has been flagged
    // go directly to the second clip
    gotoAndPlay("_secondClip2"); 
  }  // end "if buttonsClicked == false"
  // the button has been clicked, so flag the button
  buttonsClicked[0] == true; 
} // end on (release)

// etc.

Hope something here gives you some ideas.

Wow, aurelius–

Thanks for the awesome response and suggestion. I really appreciate the time you took to compose it.

With a few minor tweaks and alterations, I was able to glean EXACTLY what I needed.

Thanks again!

Cool. :slight_smile: