Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-13-2009, 02:04 PM   #1
Jerry62712
Senior Member
 
Jerry62712's Avatar
 
Join Date: Nov 2008
Posts: 186
Default How do I trap a mouse event?

I trap keyboard events so that the tab key can move the view port. This is needed so non-mouse users can move around the form.

The problem is this locks out mouse users. Once an item has focus, it has to remain on the screen even though you are trying to move the form down with the mouse as 95% of the people will be doing.

The class that allows keyboard and disallows mouse events is AutoScroll12.as that I got from Adobe tech support. What I would like to do is modify it so that if you are doing a keyboard event (usually the tab key) it works to move the view port. If you are doing a mouse event (usually scrolling down or up), that script will be ignored.

I tried adding this:
if (event is MouseEvent)
return;
at the top of the script so that if it were a mouse event, the rest of the script would be ignored, but it didn't seem to work. Using the mouse still resulted in a lot of flickering of the screen and no shifting down of the view port.

Here is the full script:
Code:
package DHSclasses {
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.core.Container;

	public class AutoScroll12 {
		public static function autoScroll12(event : Event) : void {
			var container : Container = Container(event.currentTarget);
			var focusItem : DisplayObject = DisplayObject(container.focusManager.getFocus());

			if (event is MouseEvent)
				return; // this doesn't work

			if(container.verticalScrollBar && focusItem) {
				if( focusItem == container || !container.contains(focusItem) ) {
					return;
				}

				var focusTopEdge : int = focusItem.y;
				var thisItem : DisplayObjectContainer = focusItem.parent;

				while(thisItem != container) {
					focusTopEdge += thisItem.y;
					focusTopEdge += 10;				// move page down a little
					thisItem = thisItem.parent;		// JD/DHS 11/12/09
				}

				var focusBottomEdge : int = focusTopEdge + focusItem.height;
				var scrollbarRange : int = container.verticalScrollBar.maxScrollPosition;
				var visibleWindowHeight : int = container.height;
				var lastVisibleY : int = visibleWindowHeight + container.verticalScrollPosition;
				if(container.horizontalScrollBar) {
					lastVisibleY -= container.horizontalScrollBar.height;
				}
				if( focusTopEdge == container.verticalScrollPosition ) {
					
				}
				else if( focusTopEdge < container.verticalScrollPosition ) {
					container.verticalScrollPosition = focusTopEdge;
				}
				else if( focusBottomEdge-lastVisibleY > 0 ) {
					var newPos : int = Math.min(scrollbarRange, container.verticalScrollPosition + (focusBottomEdge-lastVisibleY));
					container.verticalScrollPosition = newPos;
				}
				else {
				}
			}	// must have a scroll bar to bother with
		}		// function autoScroll12
	}			// class AutoScroll12
}				// package DHSclasses
Jerry62712 is offline   Reply With Quote
Old 11-15-2009, 07:57 PM   #2
suchislife801
Registered User
 
Join Date: Nov 2009
Posts: 17
Default

If you want to trap all mouse events inside your container use this method:

ActionScript Code:
container.mouseChildren = false; container.mouseEnabled = false;

This action trap all the mouse listeners.
suchislife801 is offline   Reply With Quote
Old 11-16-2009, 03:13 PM   #3
Jerry62712
Senior Member
 
Jerry62712's Avatar
 
Join Date: Nov 2008
Posts: 186
Default

Quote:
Originally Posted by suchislife801 View Post
If you want to trap all mouse events inside your container use this method:

ActionScript Code:
container.mouseChildren = false; container.mouseEnabled = false;

This action trap all the mouse listeners.
Just to make sure I understand, if I code that I will be able to trap a mouse event such as scroll, mouse down, etc and then pass them up to the OS. How do I identify an event as a mouse event?

As I had said, I want to bypass the processing in AutoScroll12.as if the user wants to reposition the window using the mouse. That class will reposition the window if the user uses a keyboard (usually tab) event.
Jerry62712 is offline   Reply With Quote
Old 11-16-2009, 03:34 PM   #4
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

What was this function supposed to do?
OK... think I's starting to understand... well, first just FIO: Safari on PC and any browser on Mac don't dispatch scroll events to Flash (if you mean scroll == rolling the mouse wheel). There is a workaround for it by injecting the JavaScript into HTML wrapper. I can post that when I'm home.

I'm not clear on what sort of event you ware expecting to handle (move | drag | register the mouse-down and then move the object until mouse-up | actually scroll), can you be more specific?

Also, you need to show how you intended to use that function... maybe it never gets mouse events... Or, better ask, why do you believe it should get mouse events?
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it

Last edited by wvxvw; 11-16-2009 at 03:45 PM.
wvxvw is offline   Reply With Quote
Old 11-16-2009, 03:51 PM   #5
Jerry62712
Senior Member
 
Jerry62712's Avatar
 
Join Date: Nov 2008
Posts: 186
Default

AutoScroll12.as is designed (by Adobe or at least they gave it to me) to allow the keyboard to be used to position the view port. Without it, if your form is longer than the browser allows, you can tab, but you will not see what you are tabbing to. With the class the view port will move up or down to accomodate the movement of what has focus.

The major problem is while this allows the 5% of the people that can't use a mouse to work, it blocks the 95% of the people that do. The issue becomes the mouse can't move the view port beyond the limit of the current object that has focus.

What I want to do is put in a trap in AutoScoll12.as so that the class is ignored if you are moving the view port with a mouse (therefore having a mouse event). I envision something at the top of AutoScroll12.as that would look like this:

if (event is MouseEvent)
return;

This would leave the class before it grabs the event looking for a keyboard event. While the above is syntactically correct in that no error is flagged, it also doesn't work in that the return is never executed despite using the mouse.
Jerry62712 is offline   Reply With Quote
Old 11-16-2009, 04:46 PM   #6
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

Again... you need to show how you are using what you have... because, if you haven't added that function as a handler for scroll event, or any other mouse event for that case, the condition you put there will never evaluate to true. More then that, even if it occasionally will evaluate to true, that won't cancel that on another even, when it won't evaluate to true it will work as it works now. As I'm not clear about what you're doing with that function, I cannot really tell what is wrong...
I can imagine you could've added it as a focusIn handler, or maybe added as a Tab keyDown handler, or maybe did something else - but unless you tell what you actually did with it, there's no way to tell you what you did wrong

Can you elaborate on what are you calling "view port"? is that some specific component you are dealing with, or is it the entire SWF, or the HTML page?
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it

Last edited by wvxvw; 11-16-2009 at 04:48 PM.
wvxvw is offline   Reply With Quote
Old 11-16-2009, 06:05 PM   #7
Peter Cowling
quantum tunneler
 
Join Date: Sep 2008
Location: London, UK
Posts: 882
Default

As wvxvw states really. I'll just add something that might help...

The script you have prevents something from happening, and you seem happy that it does that job.

What you want to do is a 'level' above the script. So what you need to do is add some logic before invoking the script. The logic in question needs to be able to recognize whether the user is trying to use the mouse or the keyboard. That is the place to do the work, IMO, rather than try to add it to the AutoScroll12.as.

Again, as wvxvw states, whether the logic needs to be specific to the application (I guess so based on what you say, but am not sure), or just for some specific component(s)...well whichever it is, that would be the right 'level' to work at.
Peter Cowling is offline   Reply With Quote
Old 11-19-2009, 08:17 PM   #8
Jerry62712
Senior Member
 
Jerry62712's Avatar
 
Join Date: Nov 2008
Posts: 186
Default

I'm sorry for this late reply. I just got that part all fixed and the next problem involved a LOT of typing.

I can give you a detailed explaination of the problem and solution if you would like. BTW, "view port" means the area you can view based in the browser. Your form may be longer than can fit on the visible area so you have to scroll around to see it all.

The AutoScroll.as class from Adobe allows you to move that viewable area using the keyboard. The default without it is the tab will move down (or up), but not scroll the visible area so you can't see what has focus. The problem is AutoScroll.as locks the visible portion of the browser so you can't mouse lower or higher than any area beyond where the focus control fits on the visible screen.

The solution was to remove the event listener that was suggested (change) and add the scroll listener. Then in AutoScroll.as add a test for the event and if it were a scroll event then just leave the function. If it were not, then let the function adjust the visiable view area as needed.
Jerry62712 is offline   Reply With Quote
Old 11-19-2009, 08:21 PM   #9
Jerry62712
Senior Member
 
Jerry62712's Avatar
 
Join Date: Nov 2008
Posts: 186
Default

Quote:
Originally Posted by Peter Cowling View Post
The script you have prevents something from happening, and you seem happy that it does that job.
I'm not sure why you would say I was happy it wasn't working right. I am happy that AutoScroll.as allows the keyboard to move the visible area of the browser. And I'm happy that I can now get AutoScroll.as to ignore mouse events so I can move the visible area using the mouse.

And I should give a big shout out to Adobe tech support who was great in helping solve this problem!
Jerry62712 is offline   Reply With Quote
Old 11-20-2009, 12:03 PM   #10
Peter Cowling
quantum tunneler
 
Join Date: Sep 2008
Location: London, UK
Posts: 882
Default

Quote:
Originally Posted by Jerry62712 View Post
I'm not sure why you would say I was happy it wasn't working right. I am happy that AutoScroll.as allows the keyboard to move the visible area of the browser. And I'm happy that I can now get AutoScroll.as to ignore mouse events so I can move the visible area using the mouse.

And I should give a big shout out to Adobe tech support who was great in helping solve this problem!
Well that was not what I was trying to say, but it does not matter anyhow if you know have this fixed.
Peter Cowling 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 11:51 AM.

///
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.