Skip to main content
Participating Frequently
May 28, 2009
Answered

Noob help: Triggering Movie Clips with Buttons

  • May 28, 2009
  • 1 reply
  • 932 views

Hi guys,

I'm taking an intro Flash and Action Script class and for my final I need to create a portfolio project that contains 5 unique buttons that trigger 5 unique movie clips. I'm having a hard time with this. I've been able to trigger the 1st movie clip with the first button (although I can't stop it) but I can't trigger any ohter movies with any other buttons.

Here's my code:

stop();
chuck1_btn.addEventListener(MouseEvent.CLICK, playMovie);

function playMovie(event:MouseEvent):void

{
    spaceship_mc.play();
}

chuck2_btn.addEventListener(MouseEvent.CLICK,playSaucers);


function playSaucers(event:MouseEvent):void
{
    saucers_mc.play();
}

Nothing happens when I click on chuck2_btn when I test the movie. I think I need to create a variable or class but I'm not sure. I'm a super noob with this stuff. Any thoughts? Thanks!

Rick

This topic has been closed for replies.
Correct answer Ned Murphy

I think this is what you mean. I've never used the visible propert so I'm not sure how to write out that code. All of my movie clips are on different layers on frame 1.


You should learn how to use the Help documentation to find answers like how to use the visible property.  For the code you showed earlier, here's what you can try in frame 1 to replace it.

stop();

spaceship_mc.visible = false;

saucers_mc.visible = false;

slideshow_mc.visible = false;


chuck1_btn.addEventListener(MouseEvent.CLICK, playMovie);

function playMovie(event:MouseEvent):void

{

     spaceship_mc.visible = true;

     saucers_mc.visible = false;

     slideshow_mc.visible = false;
    spaceship_mc.play();
}

chuck2_btn.addEventListener(MouseEvent.CLICK,playSaucers);


function playSaucers(event:MouseEvent):void
{

     spaceship_mc.visible = false;

     saucers_mc.visible = true;

     slideshow_mc.visible = false;
    saucers_mc.play();
}

etc...

It could be refined, like having a function that hides everything and using that every time before making the one you need to show visible.  You might find it necessary to include telling the movies to gotoAndStop(1) as well.

That's about as generous as I'm going to get.  It's important that you learn things, and handing you a solution isn't going to help do that.

1 reply

Ned Murphy
Legend
May 28, 2009

There's nothing wrong with your code, so are you getting any error messages?

ricksox79Author
Participating Frequently
May 28, 2009

Thank you very much for responding. I am getting an error in the compiler panel:

1120: Access of undefined property saucers_mc            saucers_mc.play();

It's nice to know I'm on the right track! I saw a similar thread that you respnded to that seems to relate to what I am trying to do.

http://forums.adobe.com/thread/431340?tstart=0

Basically, I just need 5 buttons to trigger 5 MC's. So far I have 3 MC's on the same layer starting on differnt keyframes (1, 21, 41). The fisrt movie is a simple motion tween MC, the second is similar accept it has a motion guide on it, and the third is a slideshow with forward and back buttons nested inside it.

Rick

Ned Murphy
Legend
May 28, 2009

There are only a few possible causes for this problem when the code is right.  And the error message was nice enough to idenyify who's missing.  Either you haven't assigned an instance name to the movieclip (in the properties panel), or the movieclip isn't in the same place on the timeline as the code.  There is another possible problem, but check those first.