Mouse Listeners or not?

In MX, I need to run a function only if and when the mouse is hovering over anything on the stage for 5 seconds or more.

How to I test for that?

ta.
blu.
LVL 39
blue-genieAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OBCTCommented:
First of all add this bit of code into the frame you want to have the trace in:

_root.wait = 5

Now make a new movie clip, it doesn't have to contain any content because you will use this as an engine to run the trace.
In the first frame of the movie clip, add this code:

onClipEvent (enterFrame) {
      if (_root.delay) {
            if (Math.floor(getTimer()/1000) == _root.lastTime+5) {
                  _root.delay = false;
            }
      } else if (Math.floor(getTimer()/1000) == _root.lastTime+_root.wait) {
            _root.lastTime = Math.floor(getTimer()/1000);
            _root.delay = true;
            trace(_xmouse);
            trace(_ymouse);
      }
}

I found this bit of code from a tutorial I did a while ago, then played around with it until I got it to suit your needs.
If you have any problems let me know.

Cheers

-OBCT
OBCTCommented:
Sorry dont add that code in the movie clip, add it in the main scene as actions for the MC

Cheers

-OBCT
OBCTCommented:
Just to add onto that bit of code, its probably a good idea to use this as the trace:

trace("_x = " + _xmouse);
trace("_y = " + _ymouse);

That will just keep you from getting confused.

Cheers

-OBCT
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

blue-genieAuthor Commented:
no OBCT, that code is buggy.

it sets delay to true even when the mouse is moving around the screen.
blue-genieAuthor Commented:
let me explain a little better.

onRollover of various movieclips and buttons on the screen, they call a playAudio function, but the function must only be called if the mouse is over that particular movieclip or button for 5 seconds or more.
negatyveCommented:
just to test. in the first frame of your movie:

_global.setExecutionDelay = function(custom_string)
{
      remExecutionDelay();
      _global.intervalID = setInterval(_global, "executeMyFunction", 2000, custom_string);
};
_global.remExecutionDelay = function()
{
      clearInterval(_global.intervalID);
};
_global.executeMyFunction = function(custom_string)
{
      trace(custom_string);
      remExecutionDelay();
};


on button 1:

on(rollOver){
      setExecutionDelay("custom_string_1");
}
on(rollOut){
      remExecutionDelay()
}


on button 2:

on button 1:

on(rollOver){
      setExecutionDelay("custom_string_2");
}
on(rollOut){
      remExecutionDelay()
}
blue-genieAuthor Commented:
Hey, i tried that but I don't think I understand that too well.

Negatyve, let me explain how the architecture of this project.

I have at _level0 the movie that controls everything, it loads movies on top of itself, and in _level0, there is a global.playAudio, which other levels refer to using theRooter.playAudio("audiolinkage") where theRooter is a global refering to _level0.

on all other layers (there's about 40) when i rollover a button or movieclip, it must check whether the mouse if over it for more than 2 seconds, if yes then it must call the playAudio function. i tried using setIntervals which worked a little bit, but at times it seemed to keep playing every 2 seconds. I don't know if i need a new interval ID in each case, if so that would be very cumbersome.

pls, if you think of something, i'll be most grateful.

ta.
blu.
negatyveCommented:
That's ok. In the main movie:

_global.theRooter = _level0;
theRooter.playAudio = new Sound();

theRooter.setExecutionDelay = function(linkage)
{
      theRooter.remExecutionDelay();
      theRooter.intervalID = setInterval(theRooter, "executeMyFunction", 2000, linkage);
};
theRooter.remExecutionDelay = function()
{
      clearInterval(theRooter.intervalID);
      theRooter.playAudio.stop();
};
theRooter.executeMyFunction = function(linkage)
{
      remExecutionDelay();
      theRooter.playAudio.stop();
      theRooter.playAudio.attachSound(linkage);
      theRooter.playAudio.start(0, 999);
};


To any button you want to be envolved:

on(rollOver){
      theRooter.setExecutionDelay("loop");
}
on(rollOut){
      theRooter.remExecutionDelay();
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
blue-genieAuthor Commented:
Negatyve, i've just seen the error of my ways.

my approach was...

on (rollOver) {
      delay = setInterval(theRooter.playAudio, 1000, "_continue");
}
on (rollOut) {
      clearInterval(delay);
}

the reason it wasn't clearing all the time was because I didn't include a clear in the press /release handler, as the press/release handler was navigating to other levels, it wasn't clearing, thus playing still.

i've kept a copy of your code, and i'll try it as soon as i can, if it also works you'll get your points then ok.

ta :-)
blu
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.