How do I create rollover events in actionscript 3.0 in the DOCUMENT CLASS, not the timeline

552 Views Asked by At

I have an animation that I want to function as button and I want it to play the animation when there is a rollover event. I have no clue how to do this.

So far I have this:

package
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    public class optbtn
    {
        public function optbtn()
        {
            //
        }
    }
}
1

There are 1 best solutions below

5
On

in your constructor would be where I would start, although you could add the listeners in a another function called from your constructor instead.

package
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    public class optbtn
    {
        public function optbtn()
        {
             addEventListener( MouseEvent.ROLL_OVER, onRolloverResponse )
        }

        private function onRolloverResponse( e:MouseEvent ):void
        {
            // do something here when rolled over
            // e.target is the object that was rolled over
            // so if you wanted it to play, you might call
            // e.target.gotoAndPlay( 2 );
        }
    }
}

Class names are typically capitaized, ie Optbtn rather than your optbtn