Solved

Mouse Listeners or not?

Posted on 2003-11-28
9
269 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:blue-genie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 9

Expert Comment

by:OBCT
ID: 9837668
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
 
LVL 9

Expert Comment

by:OBCT
ID: 9837678
Sorry dont add that code in the movie clip, add it in the main scene as actions for the MC

Cheers

-OBCT
0
 
LVL 9

Expert Comment

by:OBCT
ID: 9837708
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Author Comment

by:blue-genie
ID: 9837838
no OBCT, that code is buggy.

it sets delay to true even when the mouse is moving around the screen.
0
 
LVL 39

Author Comment

by:blue-genie
ID: 9837905
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
 
LVL 27

Expert Comment

by:negatyve
ID: 9839464
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
 
LVL 39

Author Comment

by:blue-genie
ID: 9848497
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
 
LVL 27

Accepted Solution

by:
negatyve earned 70 total points
ID: 9848805
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
 
LVL 39

Author Comment

by:blue-genie
ID: 9849052
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

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question