With the mouse events, you may want to consider adding a timer to differentiate between clicks and drags (shown in example).
// Necessary imports for this example - I use Flash Builder, so I'm not sure what CS5 requires.import flash.display.DisplayObject;import flash.events.MouseEvent;import flash.events.TransformGestureEvent;import flash.geom.Point;import flash.ui.Multitouch;import flash.ui.MultitouchInputMode;import flash.utils.getTimer;publicclassScrollExample{// The image or other display object you want to scrollprivatevar t:DisplayObject;// Dragging variablesprivatevar _prevX:Number;// Not required in this case since we're only scrolling verticallyprivatevar _prevY:Number;privatevar _dragging:Boolean=false;privatevar _lastMouseEvent:int;// Minimum touch time to permit drag (in milliseconds) - I useprivatestaticconst MIN_DRAG_TIME:Number=150;publicfunctionScrollExample(){// Switch multitouch mode to support gestures (touch/mouse events are still registered)Multitouch.inputMode =MultitouchInputMode.GESTURE;// For my applications, I have found that the stage is much more responsive to touch events, but you may want to change "stage" here to "t"// Pan Gesture - two fingers up and down - like the scroll on a Mac
stage.addEventListener(TransformGestureEvent.GESTURE_PAN, onPan);// Mouse down, move, and up - one finger drag
stage.addEventListener(MouseEvent.MOUSE_DOWN, onStartDrag);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMoveDrag);
stage.addEventListener(MouseEvent.MOUSE_UP, onStopDrag);}privatefunction onPan(e:TransformGestureEvent):void{// Move target display object by equivalent offset from pan object// For only vertical scrolling, don't use X!//t.x += e.offsetX;
t.y += e.offsetY;}privatefunction onStartDrag(e:MouseEvent):void{// Start timer to differentiate between click and drag
_lastMouseEvent = getTimer();// Start dragging
_dragging =true;// Set drag location values to track how drag is occuring// For only vertical scrolling, don't use X!//_prevX = e.stageX;
_prevY = e.stageY;}privatefunction onMoveDrag(e:MouseEvent):void{// If mouse down for less than minimum time, don't dragif(getTimer()> _lastMouseEvent + MIN_DRAG_TIME && _dragging){// Move target display object to a valid location - prevents scrolling too far// Not using X...// t.x = ValidXDragPosition(e);
t.y =ValidYDragPosition(e);// Reset drag position values
_prevX = e.stageX;
_prevY = e.stageY;}}privatefunction onStopDrag(e:MouseEvent):void{// Stop dragging
_dragging =false;// If mouse down time was less than min time, count as clickif(getTimer()<= _lastMouseEvent + MIN_DRAG_TIME){
onClick(e);}}privatefunction onClick(e:MouseEvent):void{// Handle your click event here...}// This function prevents your target display object from moving too far// In this example, it stops dragging when the display object boundary is reached// (Only showing Y direction)privatefunctionValidYDragPosition(e:MouseEvent):Number{// Get the requested drag amountvar requestedPoint:Number= _prevY - e.stageY;if(t.y - requestedPoint >0){// If drag will move target too far down, stop at top of objectreturn0;}elseif(t.y - requestedPoint < stage.stageHeight - t.height){// If drag will move target too far up, stop at bottom of objectreturn stage.stageHeight - t.height;}else{// Otherwise, allow drag by requested amountreturn _map.y - requestedPoint;}}}