Flash mouse position
- Started
- Last post
- 20 Responses
- welded
When the cursor is over the stage I want to trigger a function and then another function when it rolls out.
I have a couple ideas for this and I think the best one is to find the x and y position of the mouse and if both are greater than 0 assume the user is over the stage, otherwise assume they aren't.
ie.
if(_xmouse > 0 && _ymouse > 0) {
this.function
} else {
that.function
}Does this sound like a reasonable solution, and if so, what's the best way to keep checking these values?
Thanks.
- ********0
If you're not on the stage it won't trigger any mouse position so you may come a bit unstuck
- jpea0
If you're not on the stage it won't trigger any mouse position so you may come a bit unstuck
mimeartist(Sep 10 07, 23:56)
yep, if your not above the swf, it doesn't have focus on the html page, and you can't get any info about it.
- st33d0
You can only do this with javascript I think.
Which will mean it will break in some browsers.
This is an often asked question which has no solution.
- ********0
there are loads of things you can do to try and get around it though... if your choices are via the mouse all the time, then you can check for if the mouse is near the border of the swf and whether it has moved for a set amount of counts? that can help to show that the user moused off the page, and the mouse hasn't moved as it is not on the swf
not foolproof... but again depends on your interaction taking place
- welded0
Thanks for the tips. The first thing I tried was to make an object roughly the size of the stage and trigger onRollOver/Out, and that part works in a way, but as soon as the user mouses over another object, like a button, the onRollOut function is fired, thus defeating the whole purpose. :\
The thing is only one frame, but I suppose I could tack a couple frames on and make a noob loop to constantly get the coordinates, but that seems pretty kludgy. If there's a more elegant way, I'm all ears, but at least this way I can get the coords more than once!
Thanks again.
- fyoucher10
You can do it with AS3. Check the help section or google it. onStageOut or something like that. You can also do it with javascript and checking to see if you are rolling out of a div and pass function to swf.
- fyoucher10
If ur on AS2 another quick and dirty solution (not recc but may work) is to create a 1 pixel border around the Stage. Create a function that checks mouse position when it gets 'near' the stage bounds. The n create a function that checks hit test for that 1 pixel border at a really fast interval when it is within those bounds. onEnterFrame wont work correctly since the mouse moves faster than ur frame rate. Give that a try it may work it may not.
- PrayStation0
just a quick sample : nothing fancy
- welded0
The FLA wouldn't open for me, but I could see enough of the code in Gordon to get the gist of it. I've got some tweaking to do later, but onMouseMove seems to be just what I was looking for.
Thanks!
- PrayStation0
that's because I'm using CS3 (flash 9)
I re-uploaded the file using Flash 8
- maximillion_0
// this place has certainly gone down hill, you got PrayStation handing out flash help now
jk just incase you missed the //
- welded0
Sweet meat. My creaky old PB doesn't have the hutzpa to run CS3. :\
Thanks again.
- gdodds0
The Mouse won't detect if its outside of the swf. Best thing to do is make a hit area (or mouse coordinates) that are maybe 10-20 pixels smaller than your window size (fake it visually). Then detect if the mouse is outside of the main hit area. Otherwise set a slow interval that detect is the mouse is the stage area. If you mouse the mouse outside the stage it will let you know and you can call your function.
- welded0
gdodds, that's basically what I've got at this point. Basically I'm checking to see if the mouse is inside an area equal to the stage minus 25px on each edge and that seems to work quite well, but I haven't had chance to error proof it. After all, I'm SUPPOSED to be working on my company's corporate stuff, not my personal site. ;)
- gdodds0
The only issue will be if you move the mouse too quickly, it probably won't detect the rollOut. I would suggest trying the interval check. Start slow and then increase the speed as needed, if it doesn't detect fast enough.
- welded0
That's the plan. :)
The most important stuff is working, so the rest is cake. In this particular application it's not super important that it be 100% fool proof, but those details bug me if they aren't implemented.
- maximillion_0
use the mouse listener event to detect if the mouse x or y is in the first or last 10-20 pixels of the stage - better than rollover events
- PrayStation0
ok if you download the file again - I added a setinterval and clear interval that fires a 3rd function if no movement is detected -- for example moving off browser.
- welded0
Should I be expecting an invoice for all this? ;)
- PrayStation0
I don't know... can you afford me ?
if yes then my address for the check is...