Flex ScrollView
/**
* Author: Kevin Luo
* Email: [email protected]
* Description:
* The passed in conponent can be scroll as iphone style;
* */
package util
{
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.containers.Canvas;
public class ScrollView extends Canvas
{
private var _displayObj:DisplayObject;
private var isMouseDown:Boolean=false;
private var mDY:int;
private var sY:int;
private var eY:int;
private var mDX:int;
private var sX:int;
private var eX:int;
private var isDragging:Boolean=false;
private var sTime:Number;
private var eTime:Number
private var inertialTimerY:Timer;
private var inertialTimerX:Timer;
private var speedY:Number;
private var speedX:Number;
private var a:int;
public function get displayObj():DisplayObject
{
return this._displayObj;
}
public function ScrollView(value:DisplayObject, a:int=50)
{
super();
this.horizontalScrollPolicy="off";
this.verticalScrollPolicy="off";
this._displayObj=value;
this.a=a;
this.addChild(value);
this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandle);
this.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandle);
this.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandle);
this.inertialTimerY=new Timer(30);
this.inertialTimerX=new Timer(30);
this.inertialTimerY.addEventListener(TimerEvent.TIMER, inertialMovePieceY);
this.inertialTimerX.addEventListener(TimerEvent.TIMER, inertialMovePieceX);
}
protected function mouseDownHandle(e:MouseEvent):void
{
this.isMouseDown=true;
this.mDY=mouseY;
this.mDX=mouseX;
if (inertialTimerY.running)
inertialTimerY.stop();
if (inertialTimerX.running)
inertialTimerX.stop();
}
protected function mouseUpHandle(e:MouseEvent):void
{
this.isDragging=false;
this.isMouseDown=false;
this.eTime=new Date().time;
this.eY=mouseY;
this.eX=mouseX;
this.speedY=(eY - mDY) / (eTime - sTime) * a;
this.speedX=(eX - mDX) / (eTime - sTime) * a;
if (inertialTimerY.running)
inertialTimerY.stop();
if (inertialTimerX.running)
inertialTimerX.stop();
if (Math.abs(speedY) > 20)
{
inertialTimerY.start();
}
if (Math.abs(speedX) > 20)
{
inertialTimerX.start();
}
}
private function mouseMoveHandle(e:MouseEvent):void
{
if (this.isMouseDown)
{
if (Math.abs(mouseY - mDY) > 3 || Math.abs(mouseY - mDX) > 3)
{
if (!this.isDragging)
{
sY=mouseY;
sX=mouseX
this.isDragging=true
this.sTime=new Date().time;
}
this._displayObj.y=this._displayObj.y + (mouseY - sY);
this._displayObj.x=this._displayObj.x + (mouseX - sX)
this.sY=mouseY
this.sX=mouseX
if (this._displayObj.y > 0)
{
this._displayObj.y=0;
}
else if (this._displayObj.y < -(this._displayObj.height - this.height))
{
this._displayObj.y=-(this._displayObj.height - this.height)
}
if (this._displayObj.x > 0)
{
this._displayObj.x=0;
}
else if (this._displayObj.x < -(this._displayObj.width - this.width))
{
this._displayObj.x=-(this._displayObj.width - this.width)
}
if (this._displayObj.hasOwnProperty("selectedItem"))
{
this._displayObj["selectedItem"]=null;
}
}
}
}
private function inertialMovePieceY(evt:TimerEvent):void
{
this._displayObj.y+=speedY;
speedY=speedY * 0.9;
if (this._displayObj.y > 0)
{
this._displayObj.y=0;
inertialTimerY.stop()
}
else if (this._displayObj.y < -(this._displayObj.height - this.height))
{
this._displayObj.y=-(this._displayObj.height - this.height)
inertialTimerY.stop()
}
}
private function inertialMovePieceX(evt:TimerEvent):void
{
this._displayObj.x+=speedX;
speedX=speedX * 0.9;
if (this._displayObj.x > 0)
{
this._displayObj.x=0;
inertialTimerX.stop()
}
else if (this._displayObj.x < -(this._displayObj.width - this.width))
{
this._displayObj.x=-(this._displayObj.width - this.width)
inertialTimerX.stop()
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
⭐️ Flex & OpacityThe flex CSS shorthand property sets how a flex item will grow or shrink to fit the space available in its flex containe...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.