Tweensy - pause/resume
Tweensy.pause()はTweensyで実行中の全てのアニメーションを一時停止する。Tweener.pauseAllTweens()に相当。
Tweensy.resume()はTweensyで実行中の全てのアニメーションを再開する。Tweener.resumeAllTweens()に相当。
Tweener.pauseTweens()/Tweener.resumeTweens()の様に、特定のオブジェクトのアニメーションを停止/再開する関数はないっぽい。
- ActionScript
- TestTweensy_3.as
- Source
package {
import com.flashdynamix.motion.Tweensy;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.MouseEvent;
[SWF(backgroundColor = 0x000000, width = 600, height = 400, frameRate = 30)]
public class TestTweensy_3 extends Sprite {
private var _circle:Sprite;
private var _box:Sprite;
public function TestTweensy_3() {
initCircle();
initBox();
initPauseButton();
startCircleTweensy();
startBoxTweensy();
}
private function initCircle():void {
_circle = new Sprite();
var circle:Sprite = _circle;
var graphics:Graphics = circle.graphics;
graphics.beginFill(0x0099cc);
graphics.drawCircle(0, 0, 10);
graphics.endFill();
circle.x = Math.random() * stage.stageWidth;
circle.y = Math.random() * stage.stageHeight;
addChild(circle);
}
private function initBox():void {
_box = new Sprite();
var box:Sprite = _box;
var graphics:Graphics = box.graphics;
graphics.beginFill(0x0099cc);
graphics.drawRect(-5, -5, 10, 10);
graphics.endFill();
box.x = Math.random() * stage.stageWidth;
box.y = Math.random() * stage.stageHeight;
addChild(box);
}
private function initPauseButton():void {
var button:Button = new Button();
button.label = 'Tweensy.pause()';
button.addEventListener(MouseEvent.CLICK, onButtonClick);
addChild(button);
}
private function onButtonClick(e:MouseEvent):void {
var button:Button = e.currentTarget as Button;
if (Tweensy.paused) {
Tweensy.resume();
button.label = 'Tweensy.pause()';
} else {
Tweensy.pause();
button.label = 'Tweensy.resume()';
}
}
private function startCircleTweensy():void {
var circle:Sprite = _circle;
var targetCircleX:Number = Math.random() * stage.stageWidth;
var targetCircleY:Number = Math.random() * stage.stageHeight;
var targetCircleScale:Number = 1 + Math.random() * 2;
Tweensy.to(circle, { x: targetCircleX, y: targetCircleY, scaleX: targetCircleScale, scaleY: targetCircleScale }, 1, null, 0, null, startCircleTweensy);
}
private function startBoxTweensy():void {
var box:Sprite = _box;
var targetBoxX:Number = Math.random() * stage.stageWidth;
var targetBoxY:Number = Math.random() * stage.stageHeight;
var targetBoxScale:Number = 1 + Math.random() * 3;
Tweensy.to(box, { x: targetBoxX, y: targetBoxY, scaleX: targetBoxScale, scaleY: targetBoxScale }, 3, null, 0, null, startBoxTweensy);
}
}
}
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.filters.BevelFilter;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
internal class Button extends Sprite {
private var _textField:TextField;
public function get label():String { return _textField.text; }
public function set label(value:String):void {
_textField.text = value;
updateFill();
}
public function Button() {
_textField = new TextField();
_textField.defaultTextFormat = new TextFormat('_等幅', 10, 0x333333, true);
_textField.autoSize = TextFieldAutoSize.LEFT;
_textField.x = 8;
_textField.y = 4;
addChild(_textField);
filters = [new BevelFilter(1, 45, 0xdddddd, 0xbbbbbb)];
buttonMode = true;
mouseChildren = false;
addEventListener(MouseEvent.MOUSE_UP, onButtonMouseUp);
addEventListener(MouseEvent.MOUSE_DOWN, onButtonMouseDown);
}
private function onButtonMouseUp(e:MouseEvent):void {
var button:Sprite = e.currentTarget as Sprite;
button.filters = null;
button.filters = [new BevelFilter(1, 45, 0xdddddd, 0xbbbbbb)];
}
private function onButtonMouseDown(e:MouseEvent):void {
var button:Sprite = e.currentTarget as Sprite;
button.filters = null;
button.filters = [new BevelFilter(1, 225, 0xdddddd, 0xbbbbbb)];
}
private function updateFill():void {
graphics.clear();
graphics.beginFill(0xCCCCCC);
graphics.drawRect(0, 0, _textField.textWidth + 20, _textField.textHeight + 14);
graphics.endFill();
}
}- package {
- import com.flashdynamix.motion.Tweensy;
- import flash.display.Graphics;
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- [SWF(backgroundColor = 0x000000, width = 600, height = 400, frameRate = 30)]
- public class TestTweensy_3 extends Sprite {
- private var _circle:Sprite;
- private var _box:Sprite;
- public function TestTweensy_3() {
- initCircle();
- initBox();
- initPauseButton();
- startCircleTweensy();
- startBoxTweensy();
- }
- private function initCircle():void {
- _circle = new Sprite();
- var circle:Sprite = _circle;
- var graphics:Graphics = circle.graphics;
- graphics.beginFill(0x0099cc);
- graphics.drawCircle(0, 0, 10);
- graphics.endFill();
- circle.x = Math.random() * stage.stageWidth;
- circle.y = Math.random() * stage.stageHeight;
- addChild(circle);
- }
- private function initBox():void {
- _box = new Sprite();
- var box:Sprite = _box;
- var graphics:Graphics = box.graphics;
- graphics.beginFill(0x0099cc);
- graphics.drawRect(-5, -5, 10, 10);
- graphics.endFill();
- box.x = Math.random() * stage.stageWidth;
- box.y = Math.random() * stage.stageHeight;
- addChild(box);
- }
- private function initPauseButton():void {
- var button:Button = new Button();
- button.label = 'Tweensy.pause()';
- button.addEventListener(MouseEvent.CLICK, onButtonClick);
- addChild(button);
- }
- private function onButtonClick(e:MouseEvent):void {
- var button:Button = e.currentTarget as Button;
- if (Tweensy.paused) {
- Tweensy.resume();
- button.label = 'Tweensy.pause()';
- } else {
- Tweensy.pause();
- button.label = 'Tweensy.resume()';
- }
- }
- private function startCircleTweensy():void {
- var circle:Sprite = _circle;
- var targetCircleX:Number = Math.random() * stage.stageWidth;
- var targetCircleY:Number = Math.random() * stage.stageHeight;
- var targetCircleScale:Number = 1 + Math.random() * 2;
- Tweensy.to(circle, { x: targetCircleX, y: targetCircleY, scaleX: targetCircleScale, scaleY: targetCircleScale }, 1, null, 0, null, startCircleTweensy);
- }
- private function startBoxTweensy():void {
- var box:Sprite = _box;
- var targetBoxX:Number = Math.random() * stage.stageWidth;
- var targetBoxY:Number = Math.random() * stage.stageHeight;
- var targetBoxScale:Number = 1 + Math.random() * 3;
- Tweensy.to(box, { x: targetBoxX, y: targetBoxY, scaleX: targetBoxScale, scaleY: targetBoxScale }, 3, null, 0, null, startBoxTweensy);
- }
- }
- }
- import flash.display.Graphics;
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.filters.BevelFilter;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
- internal class Button extends Sprite {
- private var _textField:TextField;
- public function get label():String { return _textField.text; }
- public function set label(value:String):void {
- _textField.text = value;
- updateFill();
- }
- public function Button() {
- _textField = new TextField();
- _textField.defaultTextFormat = new TextFormat('_等幅', 10, 0x333333, true);
- _textField.autoSize = TextFieldAutoSize.LEFT;
- _textField.x = 8;
- _textField.y = 4;
- addChild(_textField);
- filters = [new BevelFilter(1, 45, 0xdddddd, 0xbbbbbb)];
- buttonMode = true;
- mouseChildren = false;
- addEventListener(MouseEvent.MOUSE_UP, onButtonMouseUp);
- addEventListener(MouseEvent.MOUSE_DOWN, onButtonMouseDown);
- }
- private function onButtonMouseUp(e:MouseEvent):void {
- var button:Sprite = e.currentTarget as Sprite;
- button.filters = null;
- button.filters = [new BevelFilter(1, 45, 0xdddddd, 0xbbbbbb)];
- }
- private function onButtonMouseDown(e:MouseEvent):void {
- var button:Sprite = e.currentTarget as Sprite;
- button.filters = null;
- button.filters = [new BevelFilter(1, 225, 0xdddddd, 0xbbbbbb)];
- }
- private function updateFill():void {
- graphics.clear();
- graphics.beginFill(0xCCCCCC);
- graphics.drawRect(0, 0, _textField.textWidth + 20, _textField.textHeight + 14);
- graphics.endFill();
- }
- }
About this entry
You’re currently reading “Tweensy - pause/resume,” an entry on jp.ferv.blog
- Published:
- Wed, May 13th, 2009 at 12:23 AM
- Author:
- dsk
- Category:
- Web
- Tags:
- ActionScript 3.0, Tweensy
No comments
Jump to comment form | comments rss | trackback uri