View Full Version : event.mouseover question
oktoberstorms
08-07-2009, 02:19 PM
hi everyone!
i'm taking the easy way out and asking for help. after days of flash i think my brain has finally given up lol
anyways...
how can i loop a function on a mouse over. like while on mouse over flash is constantly doing "a mouse over, a mouse over, a mouse over, a mouse over.. oh its gone now" event listener? lol @ explaination, my brain has gone =/
ie. i have set a mouseover function to do a prevFrame; .... on a mc i have. whats the way to loop that function?
or i'm guessing you can't? as the mousover event can only occur once?
any ideas which way it is?
thanks a bunch =]]]]]]]]]]]]]]]]
tadster
08-08-2009, 12:34 AM
use a Timer, on mouse over start the timer on mouse out stop it.
here is an example, when the circle gets moused over, it's color keeps changing, on mouse out the color change stops:
package
{
import flash.display.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
public class MouseOverLoopExample extends Sprite
{
private var theTimer:Timer = new Timer(100, 0);
private var aButton:Sprite = new Sprite();
public function MouseOverLoopExample()
{
aButton.graphics.beginFill(0xFF0000);
aButton.graphics.drawCircle(0, 0, 25);
aButton.graphics.endFill();
aButton.x = stage.stageWidth/2;
aButton.y = stage.stageHeight/2;
addChild(aButton);
theTimer.addEventListener(TimerEvent.TIMER, theTimerFunction);
aButton.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
aButton.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
}
private function mouseOverHandler(event:MouseEvent):void
{
if (theTimer.running == false)
theTimer.start();
}
private function mouseOutHandler(event:MouseEvent):void
{
if (theTimer.running)
theTimer.stop();
}
private function theTimerFunction(evet:TimerEvent):void
{
var randomHex:Array /* of hex values */ = [0x00FF00, 0xFF0000, 0x0000FF];
aButton.graphics.clear();
aButton.graphics.beginFill(uint(randomHex[Math.floor(Math.random()*3)]));
aButton.graphics.drawCircle(0, 0, 25);
aButton.graphics.endFill();
}
}
}
oktoberstorms
08-09-2009, 02:43 PM
thanks alot for your help! i'm going to play with that idea and code, seems like a great way to do what i am after!
thanks so much =]]]]]]
oktoberstorms
08-09-2009, 04:04 PM
ok, got it working perfectly now, thanks tadster for a great idea and helpful code =]
just incase anyone my be looking for similar prevFrame/nextFrame scroller stuff in the future this works for me, maybe its not elegant coding wise but it works =]
stop();
//import needed stuff into flashplayer
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
//create a new timer variable
var theTimerLeft:Timer = new Timer(100, 0);
var theTimerRight:Timer = new Timer(100, 0);
//set event listeners
theTimerLeft.addEventListener(TimerEvent.TIMER, theTimerFunctionLeft);
theTimerRight.addEventListener(TimerEvent.TIMER, theTimerFunctionRight);
leftarrow_btn.addEventListener(MouseEvent.MOUSE_OV ER, leftarrow_onMouseOver);
leftarrow_btn.addEventListener(MouseEvent.MOUSE_OU T, leftarrow_onMouseOut);
rightarrow_btn.addEventListener(MouseEvent.MOUSE_O VER, rightarrow_onMouseOver);
rightarrow_btn.addEventListener(MouseEvent.MOUSE_O UT, rightarrow_onMouseOut);
function leftarrow_onMouseOver (event:MouseEvent) :void
{
//if button status is mouse over and timer variable is...do...
if (theTimerLeft.running == false)
theTimerLeft.start();
}
function leftarrow_onMouseOut (event:MouseEvent) :void
{
//if btn status is mouse out and timer variable is...do...
if (theTimerLeft.running)
theTimerLeft.stop();
}
//when timer var is running (mouse over btn status) then do...
function theTimerFunctionLeft(event:TimerEvent) :void
{
imgBar.prevFrame();
imgBar.prevFrame();
imgBar.prevFrame();
imgBar.prevFrame();
//4x the command makes the mc scroll faster
}
function rightarrow_onMouseOver (event:MouseEvent) :void
{
//if button status is mouse over and timer variable is...do...
if (theTimerRight.running == false)
theTimerRight.start();
}
function rightarrow_onMouseOut (event:MouseEvent) :void
{
//if btn status is mouse out and timer variable is...do...
if (theTimerRight.running)
theTimerRight.stop();
}
//if timer var is running (mouse over btn status) then do...
function theTimerFunctionRight(event:TimerEvent) :void
{
imgBar.nextFrame();
imgBar.nextFrame();
imgBar.nextFrame();
imgBar.nextFrame();
//4x the command makes the mc scroll faster
}
thanks to everyone on this forum, thats twice you've helped me out of a hole lol thanks all =]
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.