Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-05-2003, 11:33 PM   #1
V-go
Registered User
 
Join Date: May 2003
Location: Stockholm, Sweden
Posts: 30
Send a message via ICQ to V-go
Default Mouse exit stage

Hi y'all!

I'm having a pretty common problem i would think, i'm sure there's a neat solution that everyone know..

Anyhow, I want to run a function when the mouse leaves the flash stage. I can't use _xmouse/_ymouse because it stops checking when the mouse isn't there.

I can't use a button because there are other buttons that can't be interferred with their own rollOut mechanisms..

Is hitTest the solution? I'm not so knowledgable about it but perhaps..

Any tips? Thanks!

Viggo
V-go is offline   Reply With Quote
Old 06-06-2003, 02:58 AM   #2
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Howdy...

Try this file...
Attached Files
File Type: zip mouseloctest.zip (2.3 KB, 2221 views)
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 06-06-2003, 09:11 AM   #3
V-go
Registered User
 
Join Date: May 2003
Location: Stockholm, Sweden
Posts: 30
Send a message via ICQ to V-go
Default Humm, not quite what i need

That example file works just like the check _xmouse / _ymouse with stage coordinates that i've already tried.
Problem is that it's waay to unreliable. If users drag the mouse quickly out of the stage flash doesn't record the new coordinates.

Is there no other way of doing this?

My alternate solution is to check if the coordinates havn't changed for like one second and then assume the user is outside of the stage or has suddenly dropped dead.

Thanks CyanBlue for your reply!
V-go is offline   Reply With Quote
Old 06-06-2003, 09:59 AM   #4
tost
my pleasure
 
tost's Avatar
 
Join Date: Apr 2002
Location: gent.be
Posts: 792
Default

i wouldn't do that, one second is not very long. people will think you are hacking their cursor!
btw, i think we are all very happy that not every itch of movement is tracked, we wouldn't get very high framerates if it did. i don't think it's a problem really, it's not normal user behaviour to break the speed limits with the cursor
grtz_
tost
tost is offline   Reply With Quote
Old 06-06-2003, 10:05 AM   #5
V-go
Registered User
 
Join Date: May 2003
Location: Stockholm, Sweden
Posts: 30
Send a message via ICQ to V-go
Default

No no, this is a serious problem. For example, when i tried the example file, maybe 1 out of 20 times the "off stage" code triggered. It would be useless on a website where it's required to work.
V-go is offline   Reply With Quote
Old 06-06-2003, 10:56 AM   #6
sneeuwitje
...
 
sneeuwitje's Avatar
 
Join Date: May 2003
Location: rotterdam, NL
Posts: 676
Default don't mind JavaScript?

check out this link @
artificialcolors.com

maybe this could work for you.

i shouldn't really be posting this link: Only works for Win IE5+ (as far as i know).
But maybe someone can get it to work properly. My JavaScript is lousy, so i'm not gonna try now.
__________________
Little bit off-Flash lately ... back soon hopefully
sneeuwitje is offline   Reply With Quote
Old 03-08-2005, 08:52 PM   #7
ThePudge
Registered User
 
ThePudge's Avatar
 
Join Date: Mar 2005
Location: Eindhoven, The Netherlands
Posts: 2
Default

Hey V-go,

I suspect after 2 yrs you have found the answer lol.. but for all those who are looking for an answer and only find useless answers here I will show a nice trick.

I really dislike it when people give an answer to the wrong question or start complaining about framerates or mock your issue which only shows that they have no clue how to solve it.

What I do to check if the mouse has left the flash stage is to make use of a first-order predictor, like in finite element grid solvers.

For instance I used an object that followed the mouse pointer.. and in it i had the following code:

ActionScript Code:
// function called whenever mouse moves (on stage) this.onMouseMove = function() {         // calculate 1st order predictor (= 'velocity' of mouse pointer)         this.predX = _root._xmouse - this._x;     this.predY = _root._ymouse - this._y;         // sets this mouse following object to position of mouse     this._x = _root._xmouse;     this._y = _root._ymouse; } // somewhere in your code you can check if the mouse pointer left the stage // by adding the 1st order predictor to the current mouse position if (_root._xmouse+ this.predX > 800) { trace("outside stage"); }

The predictor assures that if you move your mouse too fast off the stage it will still register if it has left the stage, you can tweak it a bit, by for instance adding only half the predictor or twice the predictor if you find it is not completely accurate.

Sure tests aren't framerate friendly.. but these days you need 2GHz to type a letter in MsOffice , so you can expect ppl will use decent pcs to check out your hip website.

Good Luck,
Pudge
ThePudge is offline   Reply With Quote
Old 03-09-2005, 12:42 AM   #8
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Can you post the sample, if you don't mind, Pudge??? Love to see how it works...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 03-09-2005, 09:05 AM   #9
sneeuwitje
...
 
sneeuwitje's Avatar
 
Join Date: May 2003
Location: rotterdam, NL
Posts: 676
Default

I feel upto it now

Hey Pudge: nice thinking, but you leave Stage.scaleMode: 'noScale' unaccounted for. In effect this only works if your movie is 800px width and it scales with the Stage. But your idea tickled me a lot though, so I happily coded an adaption to 100% movie-scales (was time I did that Universal StageMargin Object anyways ... so here it is ... finally):
ActionScript Code:
Stage.scaleMode = "noScale"; var SA = Stage.align = "LC"; // deliberately set wrong scaleMode // var movieWidth = 550;// default for new .fla var movieHeight = 400;// default for new .fla with (_root) {lineStyle(1,0,100); moveTo(0,0); lineTo(0,movieHeight); lineTo(movieWidth,movieHeight); lineTo(movieWidth,0); lineTo(0,0);}; // _________________________ // BEGIN Universal StageMargin Object // for all alignments with scaleMode:'noScale' // -- private vars var scaleModes = ['T', 'B', 'L', 'R', 'TL', 'TR', 'BL', 'BR']; var correctScaleMode = false; for (var n in scaleModes) if (SA === scaleModes[n]) correctScaleMode = true; if (correctScaleMode === false) trace("***Error*** Stage.scaleMode has illegal value:"+SA+"\\n\\t\\tStageMargin Object will render unusable. Please enter one of these:"+scaleModes); var Vcenter = SA.length * Number(SA.indexOf("L") >= 0 || SA.indexOf("R") >= 0) / 2; var Hcenter = SA.length * Number(SA.indexOf("T") >= 0 || SA.indexOf("B") >= 0) / 2; var Tdiv = (SA == 'B') ? 1 : Number(SA.indexOf("T") < 0) * Vcenter; var Bdiv = (SA == 'T') ? 1 : Number(SA.indexOf("B") < 0) * Vcenter; var Ldiv = (SA == 'R') ? 1 : Number(SA.indexOf("L") < 0) * Hcenter; var Rdiv = (SA == 'L') ? 1 : Number(SA.indexOf("R") < 0) * Hcenter; // -- NEW GLOBAL: StageMargin _global.StageMargin = {left:0, right:0, top:0, bottom:0} var stageListener = {}; stageListener.onResize = function () {     var Hdiff = Stage.width-movieWidth;     var Vdiff = Stage.height-movieHeight;     StageMargin.right = Rdiv * Hdiff;     StageMargin.left = Ldiv * Hdiff;     StageMargin.top = Tdiv * Vdiff;     StageMargin.bottom = Bdiv * Vdiff; }; Stage.addListener (stageListener); stageListener.onResize(); // ##END Universal StageMargin Object // _________________________ // BEGIN mouseListener for Stage-exit // var mouseTrack = this.createEmptyMovieClip("mouseTrack", 101); with (mouseTrack) {beginFill(0,100); moveTo(-5,-5); lineTo(-5,5); lineTo(5,5); lineTo(5,-5); lineTo(-5,-5); endFill();}; var mouseListener = {}; var predX, predY; mouseListener.onMouseMove = function () {     // calculate 1st order predictor (= 'velocity' of mouse pointer)     predX = _root._xmouse - mouseTrack._x;     predY = _root._ymouse - mouseTrack._y;     // sets this mouse following object to position of mouse     mouseTrack._x = _root._xmouse;     mouseTrack._y = _root._ymouse; }; Mouse.addListener(mouseListener); // ##END mouseListener for Stage-exit // // somewhere in your code you can check if the mouse pointer left the stage // by adding the 1st order predictor to the current mouse position // // -- this onEnterFrame checks if it went off-Stage at the right side // var counter = 0; mouseTrack.onEnterFrame = function () { if (_root._xmouse + predX > movieWidth+StageMargin.right) {     predX = 0;     trace ((counter++) + ": outside stage"); } }
Code should work when pasted on 1st frame of new FLA.

Last edited by sneeuwitje; 03-09-2005 at 09:31 AM. Reason: just slashes and a faulty scaleMode ;) and comments
sneeuwitje is offline   Reply With Quote
Old 03-09-2005, 10:03 AM   #10
ThePudge
Registered User
 
ThePudge's Avatar
 
Join Date: Mar 2005
Location: Eindhoven, The Netherlands
Posts: 2
Default

Sneeuwwitje,

of course, your addition makes it complete, thanks.
I just tried to keep my example concise and simple.

Ciao.
ThePudge is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:26 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.