Asimina88
Asimina88

Reputation: 107

How to trace a message if 3 movieclips was clicked?

I am building a simple game in flash in actionscipt 3. I want when the user click on the 3 movieclips on the stage to trace a message like "Thanks for clicking all 3 movieclips!"

this message have to appear once he click on the 3 not only on one.

any ideas :)

Upvotes: 0

Views: 103

Answers (2)

crooksy88
crooksy88

Reputation: 3851

Or you could have a single function that all buttons use:

var count:uint = 0;

function buttonPress(e:MouseEvent):void {
  count++;

if (count == 3) {
trace("Thanks for clicking all 3 movieclips!");

//reset count if required
//count = 0;
}

}

Upvotes: 0

ToddBFisher
ToddBFisher

Reputation: 11610

You want to store if they have been clicked where each of you listeners can access, for example:

var clicked1:Boolean = false;
var clicked2:Boolean = false;
var clicked3:Boolean = false;

Then inside of your action listener method(s):

function listenerMethod1(e:MouseEvent):void {
  clicked1 = true;
  checkIfAllClicked();
}

function listenerMethod2(e:MouseEvent):void {
  clicked2 = true;
  checkIfAllClicked();
}

function listenerMethod3(e:MouseEvent):void {
  clicked3 = true;
  checkIfAllClicked();
}

etc... (alternatively you can handle all 3 movieClip events in the same handler method). Don't forget the checking function:

function checkIfAllClicked(){
  if(clicked1 && clicked2 && clicked3){
    trace("Thanks for clicking all 3 movieclips!");
  }
}

Depending on what you are doing you can have a reset method as well to reset all 3 to false.

If you have a big mass of movieclips you can consider using a collection, such as a Vector<Boolean>.

Upvotes: 1

Related Questions