i sort of sourced online and created a code that i thought would be suitable for vertical scrolling for a touch screen app am currently building with AS3.
it works fairly well, just that when i test it on the touch screen it isn’t so fluid and responsive to my touch.
its a movie clip (scroll_mc) that has been masked and rests in a border movie clip (stageborder)
here’s the code:
var speed:Number;
var speedArray:Array;
var prevY:Number;
var DRAG:Number = 20;
var HEIGHT:int = 360;
scroll_mc.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
function onDown(evt:MouseEvent):void {
speedArray = new Array(0,0,0,0,0,0,0,0,0,0);
speed = 0;
prevY = this.mouseY;
stageborder.addEventListener(Event.ENTER_FRAME, onDownEnter);
stageborder.addEventListener(MouseEvent.MOUSE_UP, onUp);
}
function onDownEnter(evt:Event):void {
var sp = this.mouseY - prevY;
scroll_mc.y += sp;
if (scroll_mc.y < (HEIGHT-scroll_mc.height)) {
scroll_mc.y = (HEIGHT-scroll_mc.height);
}
else if (scroll_mc.y > stageborder.y) {
scroll_mc.y = stageborder.y;
}
speedArray.push(sp);
speedArray.shift();
prevY = this.mouseY;
}
function onUp(evt:MouseEvent):void {
stageborder.removeEventListener(Event.ENTER_FRAME, onDownEnter);
stageborder.removeEventListener(MouseEvent.MOUSE_UP, onUp);
speed = 0;
for (var i:int = 0; i<speedArray.length; i++) {
speed += speedArray[i];
}
speed /= speedArray.length;
addEventListener(Event.ENTER_FRAME, onEnter);
}
function onEnter(evt:Event):void {
if (Math.abs(speed) < .5) {
speed = 0;
}
if (speed < 0) {
if (scroll_mc.y > (HEIGHT-scroll_mc.height) - speed) {
scroll_mc.y += speed;
speed -= speed/DRAG;
}
else {
scroll_mc.y = (HEIGHT-scroll_mc.height);
speed = 0;
}
}
else {
if (scroll_mc.y < 0-speed) {
scroll_mc.y += speed;
speed -= speed/DRAG;
}
else {
scroll_mc.y = 0;
speed = 0;
}
}
}
i have also attached the demo file am working on,
can anybody help me in tweaking it so the scrolling is more fluid?
thanks in advance
williams