Skip to main content
Known Participant
March 3, 2010
Question

AS3 nested mc button doesn't respond

  • March 3, 2010
  • 2 replies
  • 2167 views

I'm using AS3 timeline actions. I have a movie clip nested in another movie clip, which has five buttons. The code is on the parent movie clip's timeline. The buttons activate movie clips with tweens. I wonder why the buttons need to be clicked several times before I see the tween movie clips appear. Some times the movie doesn't even show up.

Is it a script problem or something else?

stop();
import fl.transitions.Tween;
import fl.transitions.easing.*;

pers_1.addEventListener(MouseEvent.CLICK, showMovie);
pers_2.addEventListener(MouseEvent.CLICK, showMovie);
pers_3.addEventListener(MouseEvent.CLICK, showMovie);
pers_4.addEventListener(MouseEvent.CLICK, showMovie);
pers_5.addEventListener(MouseEvent.CLICK, showMovie);

// buttons' labels
pers_1.txt.text = "Historical Perspective";
pers_2.txt.text = "Behavioral Perspective";
pers_3.txt.text = "Symbolic Perspective";
pers_4.txt.text = "Structural Perspective";
pers_5.txt.text = "Normative Perspective";


// creating tweeing
movie_1.visible=false;
movie_2.visible=false;
movie_3.visible=false;
movie_4.visible=false;
movie_5.visible=false;

function showMovie(Event:MouseEvent): void
{ switch(Event.currentTarget.name){
  case "pers_1":
  movie_1.x +=3; if (movie_1.x <=130) {movie_1.visible=true}
  var panel1:Tween = new Tween(movie_1, "x", Elastic.easeOut, 100, 245, 4, true);
  movie_2.visible=false; movie_3.visible=false; movie_4.visible=false; movie_5.visible=false;
  break;
 
  case "pers_2":
  movie_2.x +=3; if (movie_2.x <=130) {movie_2.visible=true}
  var panel2:Tween = new Tween(movie_2, "x", Elastic.easeOut, 150, 130, 4, true);
  movie_1.visible=false; movie_3.visible=false; movie_4.visible=false; movie_5.visible=false;
  break;
 
  case "pers_3":
  movie_3.x +=3; if (movie_3.x <=130) {movie_3.visible=true}
  var panel3:Tween = new Tween(movie_3, "x", Elastic.easeOut, 100, 140, 3, true);
  movie_1.visible=false; movie_2.visible=false; movie_4.visible=false; movie_5.visible=false;
  break;
 
  case "pers_4":
  movie_4.x +=3; if (movie_4.x <=130) {movie_4.visible=true}
  var panel4:Tween = new Tween(movie_4, "x", Elastic.easeOut, 100, 130, 3, true);
  movie_1.visible=false; movie_2.visible=false; movie_3.visible=false; movie_5.visible=false;
  break;
 
 
  case "pers_5":
  movie_5.x +=3; if (movie_5.x <=130) {movie_5.visible=true}
  var panel5:Tween = new Tween(movie_5, "x", Elastic.easeOut, 120, 245, 3, true);
  movie_1.visible=false; movie_2.visible=false; movie_3.visible=false; movie_4.visible=false;
  break;
 
}//switch

}//function

Please suggest ways to correct this problem,

German

This topic has been closed for replies.

2 replies

Inspiring
March 3, 2010

One of the reasons may be that txt object of the buttons takes over mouse click. You should set all the the buttons mouseChildren = false either on timeline or, better as a part of object instantiation:

pers_1.mouseChildren = false;

kglad
Community Expert
Community Expert
March 3, 2010

are you checking those if-conditions?

german01Author
Known Participant
March 3, 2010

Andrei and Kglad:

Thanks for replying.

Andrei, I did have all buttons mouseChildren= false. Buttons are copies of a movie clip with _up, _over, and _down states. So inside each button I have:

stop();
buttonMode=true;
mouseChildren=false;

The problem still continues.

Kglad:

Can you please give me an example of how to check the if's?

I thought the final position of each movie clip would check for the if's, but obviously it isn't correct.

German

kglad
Community Expert
Community Expert
March 3, 2010

those movieclips are only made visible when their x property is < 130.  have you checked their x position when they fail to be made visible?