Val Head - Designer, Consultant and Speaker.

AS3 – calling a custom event from the timeline

This is kind of a follow up to my last post on writing a custom event in AS3. The sample files show how to call a custom class from the timeline . (The same code would apply to calling a built-in event from the timeline as well.) When would this come up? Most likely when you have some kind of animation build up that has to play out before buttons or other objects can become active.

The sample file features a movie clip that animates (via a timeline tween) across the stage and then dispatches an event when it finishes it’s tween.

Calling event from the timeline sample files

A basic custom class with AS3

These files are from my presentation at the Pittsburgh Flash User Group (PittMFUG) tonight.

There are two sets of example files, both showing very basic custom events in AS3 — hence the name “BareBonesEvent”.

The first set (01 really basic) is an example of BareBonesEvent that is fired after the mouse is clicked 5 times. Nothing fancy there at all. But, if you’re looking for minimal custom event code, this is it.

The second set (02 basic wProperty) steps it up just a little. The BareBonesEvent is dispatched after the mouse is clicked five times again. But this time we also move a graphic a few pixels and pass the graphics new x position along with the event object.

BareBonesEvent sample

ETA: If you’re wondering what happens if you don’t override the clone method, there’s a post on the bit-101 blog that explains a bit about what could happen: bit-1o1