views:

322

answers:

2

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

+2  A: 

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(); 
}
Allan
Thats great info, I was wondering about how to get the hand to show up after some experimenting. I'll give that a go an see how I get along. Thanks Allan
whamo
This has been working well and has reduced my timeline size a lot. On some objects I am getting this error when they are clicked:"ReferenceError:Error #1069: Property play not found on flash.display.SimpleButton"Do you have any ideas why that is happening? Thanks
whamo
yep, this is because you are calling the function play() on a SimpleButton. SimpleButtons do not have a function play() as they do not inherit from MovieClip. http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/SimpleButton.htmlTo fix this make them MovieClips (be careful about changing an existing Button to MovieClip as this does not work). Just copy your contents into a new MovieClip.
Allan
Thanks mate, I realised some of my objects had buttons within them. Have been through and made everything graphics. My timeline is now 1 frames long instead of 100+. Cheers for the help
whamo
A: 

Hi,

I would say different MovieClips for different state will be better as you might want need some other states also(Disabled, Hovered, Clicked etc...). Different MovieClip on different state would also help you your code organized and will be much easier to modify individual MovieClip of states rather than inserting and deleting multiple frames in timeline.

So, My suggestion is

-Make standard or Custom Button -Put different MovieClips for Different states(either you swap them on event listener or If default Button, put on timeline) -Add animation in those separate State MovieClips.

You would also reuse same animation for multiple button effectively by this way.

Bhavesh.Bagadiya