Skip navigation
Currently Being Moderated

AS3 Putting Buttons Inside Movie Clip

May 1, 2010 1:11 AM

I am practicing AS3 (after years of AS2) and am having trouble having a button inside a movie clip talk to another movie clip on the main timeline. Here is the code:

 

 

OneButton.addEventListener(MouseEvent.CLICK, OneButtonClicked);

 

function OneButtonClicked(event:MouseEvent):void

{

MovieTarget.gotoAndStop(1);

MovieDescription.gotoAndStop("One");

}

 

 

TwoButton.addEventListener(MouseEvent.CLICK, TwoButtonClicked);

 

function TwoButtonClicked(event:MouseEvent):void

{

MovieTarget.gotoAndStop(2);

MovieDescription.gotoAndStop("Two");

}

 

 

The code above works, but if I put OneButton and TwoButton inside a movie clip, I know longer can target MovieTarget and MovieDescription. The reason I want to put OneButton and TwoButton inside it's own MC is so I can dim each button after it is clicked by toggling the playhead inside that MC. Help? Thanks!

 
Replies
  • Currently Being Moderated
    May 1, 2010 1:37 AM   in reply to adobechr

    Hi,

     

    You have to target first the movieclip you put the 2 buttons in for example master_mc.oneButton.addEventListener.... master_mc.twoButton.addEventListener....

     

    you can use one function for both buttons for example :

     

    master_mc.OneButton.addEventListener(MouseEvent.CLICK, buttonClicked);

     

    master_mc.OneButton.addEventListener(MouseEvent.CLICK, buttonClicked);

     

    function buttonClicked(event:MouseEvent):void

    {

         if ( event.target.name == "master_mc.oneButton")

         {

             MovieTarget.gotoAndStop(1);

             MovieDescription.gotoAndStop("One");

          }

     

    if ( event.target.name == "master_mc.twoButton")

         {

            MovieTarget.gotoAndStop(2);

            MovieDescription.gotoAndStop("Two");

          }

    }

     
    |
    Mark as:
  • Currently Being Moderated
    May 1, 2010 2:29 AM   in reply to adobechr

    Hi,

     

    you can start of by making your button in a movieClip called button for instance.  You design it the way you want ( I would make two different frames with one button clickable, the other a  graphic (grayed out) and toggle it back and forth with a frame label) and then you drag it twice to stage and give it instance names.  Like that those 2 buttons inherited all the designs and functionality of the parent which is button.  Like that you dont have to put them in a movieClip to control both; you just control the parent one and the instances will inherit those properties and functionality.

     
    |
    Mark as:
  • Currently Being Moderated
    May 1, 2010 12:02 PM   in reply to adobechr

    Start over from the begining

     

    press  f8 and chose movieClip then draw your untoggled button call the movie button then create another movie and create your toggled button or greyed out button and call it greyedButton.  Go to main stage add 2 button instances and 2 greyedButton instances( just drag from library).  you have 4 instances on stage.  give call instance names and place one them on top of each other so u can only see 2 buttons on stage.  put the greyed button under the button.

     

    now with action script

     

     

    button1.addEventListener(MouseEvent.CLICK, OneButtonClicked);

     

    function OneButtonClicked(event:MouseEvent):void

    {

    MovieTarget.gotoAndStop(1);

    MovieDescription.gotoAndStop("One");

    button1.visible = false; //  here the greyed button will show

     

    }

     

     

    button2.addEventListener(MouseEvent.CLICK, TwoButtonClicked);

     

    function TwoButtonClicked(event:MouseEvent):void

    {

    MovieTarget.gotoAndStop(2);

    MovieDescription.gotoAndStop("Two");

    button1.visible = true; // here button1 will go back to its orignal state

    button2.visible = false // here the greyed button will show

     

    }

     
    |
    Mark as:
  • Currently Being Moderated
    May 1, 2010 12:27 PM   in reply to adobechr

    your most welcome and you

     

    ps : if you want the hand curser to show use  button1.buttonMode = true;

     
    |
    Mark as:
  • Currently Being Moderated
    May 1, 2010 1:59 PM   in reply to adobechr

    where ever you want I was just telling that there is this property for movieClips/

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points