ボタンでジャンプ + つかんでドラッグ
// forked from nacookan's つかんでドラッグしてスクロールするテスト
package{
import flash.text.*;
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
import caurina.transitions.Tweener;
[SWF(backgroundColor="0x000000", frameRate="30")]
public class TweenScrollTest extends Sprite{
public function TweenScrollTest():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);
var button:Sprite = new Sprite();
button.graphics.lineStyle(2, 0xa0a0a0);
button.graphics.beginFill(0xe0e0e0);
button.graphics.drawRect(0, 0, 100, 30);
button.graphics.endFill();
button.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void{
Tweener.addTween(image, {
time: 2,
x: -1000,
y: -500,
transition: 'easeInOutExpo'
});
Tweener.addTween(image, {
time: 1,
z: 500,
transition: 'easeOutExpo',
onComplete: function():void{
Tweener.addTween(image, {
time: 1,
z: 0,
transition: 'easeInOutElastic'
});
}
});
});
button.x = 100;
button.y = 100;
image.addChild(button);
var button2:Sprite = new Sprite();
button2.graphics.lineStyle(2, 0xa0a0a0);
button2.graphics.beginFill(0xe0e0e0);
button2.graphics.drawRect(0, 0, 100, 30);
button2.graphics.endFill();
button2.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void{
Tweener.addTween(image, {
time: 2,
x: 0,
y: 0,
transition: 'easeInOutExpo'
});
Tweener.addTween(image, {
time: 1,
z: 500,
transition: 'easeOutExpo',
onComplete: function():void{
Tweener.addTween(image, {
time: 1,
z: 0,
transition: 'easeInOutElastic'
});
}
});
});
button2.x = 1300;
button2.y = 700;
image.addChild(button2);
});
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'
});
});
}
}
}