Skip navigation
Currently Being Moderated

Making buttons that stay down.

Apr 3, 2012 2:22 AM

Tags: #help #buttons #actionscript #flash_cs5.5

Hi all,

 

You've probably had this question many times and I've done some google searches but I'm new to actionscript so I'm still rather baffled.

 

I have a document which is basically a catalogue page, and I'm trying to make it so that when you click on an image, a movieclip of the image fading in larger appears, so it will look essentially like it's been zoomed in. To do this I put the movieclip inside a button. I have the button working fine, when you click it, it does exactly what it's supposed to, but I have no idea how to set it so that when the button is clicked it stays in the 'down' position, so you don't have to hold the mouse down. And also how to get back to the main screen afterwards, since the movie does take up the entire stage when played.

 

Is it possible to do this?

 

Thanks a lot.

 
Replies
  • Currently Being Moderated
    Apr 3, 2012 5:09 AM   in reply to emmajones89

    Either do not put the movieclip inside the button or use a movieclip instead of a button symbol.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 3, 2012 12:55 PM   in reply to emmajones89

    MovieClips, Sprites, etc also can be clicked.

     

    Assuming you want to do a little coding as possible, create a new MovieClip and make it similar to the button. On frame 1 put the image in its default state. On frame 2 put the MovieClip you have of the image zooming. Now add a second layer to the MovieClip and click in frame 1. Open up the Actions Panel (Window->Actions or F9) and simply put a stop command in the actions panel:

     

    stop();

     

    Not back out on the main timeline, click on your MovieClip (what used to be a button) so you have it selected. Look in the Properties Panel (Window->Properties) and in the upper right there is a white empty box. This is where you can 'name' your MovieClip so you can use it with ActionScript. Give it a name like: image1_mc

     

    Back on your main timeline add in a new layer (if you don't already have one) for actionscript (naming it 'actions' helps). On the frame where your MovieClip appears where you want it to zoom and act like a button, click on the actions layer you made and insert a blank keyframe. Add this code:

     

    image1_mc.addEventListener(MouseEvent.MOUSE_CLICK, clickHandler);

     

    function clickHandler(e:MouseEvent):void

    {

         if (MovieClip(e.target).currentFrame == 1)

         {

              MovieClip(e.target).gotoAndStop(2);

         }

         else

         {

              MovieClip(e.target).gotoAndStop(1); 

         }

    }

     

    Should give you the basics of converting a button to a MovieClip and 'doing something' to it based on mouse over or mouse out. This will probably not be your desired effect because once you roll off the image it won't zoom back out. If you're comfortable with code there are much better ways of doing this with some AS Tweening. Although you'll start to get into dynamic positioning and I don't want to throw too much code in one post.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 6:46 AM   in reply to emmajones89

    You're welcome. If you have further button questions just shoot them out here.

     
    |
    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