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?
 
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();
}
0
 
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
0
 
OBCTCommented:
Sorry dont add that code in the movie clip, add it in the main scene as actions for the MC

Cheers

-OBCT
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
0
 
blue-genieAuthor Commented:
no OBCT, that code is buggy.

it sets delay to true even when the mouse is moving around the screen.
0
 
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.
0
 
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()
}
0
 
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.
0
 
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.