Search code examples
flashflash-cs4

Good way to make a flash button animate when clicked


This may be obvious but it's been ages since I used flash. I have an object drawn in flash lets say a clock. When the clock is clicked I want to animate the hands spinning round.

So do I create the clock as a button and call the animation on the down state? Or is it better to create a movie clip and have it act like a button? Atm I'm using listeners to listen for clicks on objects and navigate to its animation in the main timeline. If I have many objects the main timeline is going to get huge so I need a good way to make everything into movieclips but still be able to click them. I'm using CS4 AS3

Thanks


Solution

  • Make it a MovieClip. Lets say your instance name for the clock is "mcClock". Since we access the target you can use the same function handler for all your MovieClips.

    mcClock.addEventListener(MouseEvent.CLICK, handleClickOnObject);
    mcClock.buttonMode = true; //to display hand cursor
    //easily use the same functon for another MovieClip
    mcClock2.addEventListener(MouseEvent.CLICK, handleClickOnObject);
    
    function handleClickOnObject(e:MouseEvent):void
    {
         e.target.play(); 
    }