Solved

Mouse Listeners or not?

Posted on 2003-11-28
9
233 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now