Jerry62712
11-13-2009, 03:04 PM
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:
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
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:
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