/* * AnimatedRollOver class by Wade Walker. * wadedwalker.com/ * wadedwalker@gmail.com * * Copyright (c) 2006 - 2010 Wade Walker * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ package com.wadedwalker{ //--------------------------------------------------------------------------------------------------------------------------------------\\ //--------------------------------------------------------------- Imports --------------------------------------------------------------\\ //--------------------------------------------------------------------------------------------------------------------------------------\\ import flash.events.Event; import flash.events.MouseEvent; import flash.display.MovieClip; public class AnimatedRollOver extends MovieClip { //--------------------------------------------------------------------------------------------------------------------------------------\\ private var _dir:int = -1; //--------------------------------------------------------------------------------------------------------------------------------------\\ public function AnimatedRollOver() { this.addEventListener(Event.ENTER_FRAME,update); this.addEventListener(MouseEvent.ROLL_OUT,changeDir); this.addEventListener(MouseEvent.ROLL_OVER,changeDir); } //--------------------------------------------------------------------------------------------------------------------------------------\\ private function update(e:Event):void { this.gotoAndStop(this.currentFrame + _dir); if (this.currentFrame == 1) { this.removeEventListener(Event.ENTER_FRAME, update); } if (this.currentFrame == this.totalFrames) { this.removeEventListener(Event.ENTER_FRAME, update); } } //--------------------------------------------------------------------------------------------------------------------------------------\\ private function changeDir(e:MouseEvent):void { _dir = -_dir; if (this.currentFrame == 1) { this.addEventListener(Event.ENTER_FRAME, update); } if (this.currentFrame == this.totalFrames) { this.addEventListener(Event.ENTER_FRAME, update); } } } }