つかんでドラッグしてスクロールするテスト
package{
import flash.text.*;
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
import caurina.transitions.Tweener;
public class GrabDragTest extends Sprite{
public function GrabDragTest():void{
var image:Sprite = new Sprite();
image.buttonMode = true;
this.addChild(image);
var url:String = 'http://farm1.static.flickr.com/67/199819013_42eca9cf82_o.jpg';
var req:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void{
image.addChild(loader);
var credit:TextField = new TextField();
credit.htmlText = 'by <u><font color="#0000ff"><a href="http://www.flickr.com/photos/galaygobi/">galaygobi</a></font></u>';
credit.autoSize = TextFieldAutoSize.LEFT;
image.addChild(credit);
});
loader.load(req);
var startX:Number = 0;
var startY:Number = 0;
var imageX:Number = 0;
var imageY:Number = 0;
var lastX:Number = 0;
var lastY:Number = 0;
var lasttime:Number = 0;
var drag:Boolean = false;
image.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void{
startX = e.stageX
startY = e.stageY
imageX = image.x;
imageY = image.y;
drag = true;
Tweener.removeAllTweens();
});
image.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void{
if(!drag) return;
image.x = imageX + (e.stageX - startX);
image.y = imageY + (e.stageY - startY);
var t:Number = (new Date()).getTime();
if(t - lasttime < 200) return;
lastX = e.stageX;
lastY = e.stageY;
lasttime = t;
});
image.addEventListener(MouseEvent.MOUSE_UP, function(e:MouseEvent):void{
drag = false;
var now:Number = (new Date()).getTime();
if(200 < now - lasttime) return;
Tweener.addTween(image, {
time: (now - lasttime) / 1000 * 20,
x: (image.x + (e.stageX - lastX)),
y: (image.y + (e.stageY - lastY)),
transition: 'easeOutExpo'
});
});
}
}
}