Tweensy - pause/resume

Tweensy.pause()はTweensyで実行中の全てのアニメーションを一時停止する。Tweener.pauseAllTweens()に相当。
Tweensy.resume()はTweensyで実行中の全てのアニメーションを再開する。Tweener.resumeAllTweens()に相当。

Tweener.pauseTweens()/Tweener.resumeTweens()の様に、特定のオブジェクトのアニメーションを停止/再開する関数はないっぽい。

TestTweensy_3.swf

  • 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();
	}

}
  1. package  {
  2.     import com.flashdynamix.motion.Tweensy;
  3.     import flash.display.Graphics;
  4.     import flash.display.Sprite;
  5.     import flash.events.MouseEvent;
  6.  
  7.     [SWF(backgroundColor = 0x000000, width = 600, height = 400, frameRate = 30)]
  8.     public class TestTweensy_3 extends Sprite {
  9.  
  10.         private var _circle:Sprite;
  11.         private var _box:Sprite;
  12.  
  13.         public function TestTweensy_3() {
  14.             initCircle();
  15.             initBox();
  16.             initPauseButton();
  17.  
  18.             startCircleTweensy();
  19.             startBoxTweensy();
  20.         }
  21.  
  22.         private function initCircle():void {
  23.             _circle = new Sprite();
  24.  
  25.             var circle:Sprite = _circle;
  26.             var graphics:Graphics = circle.graphics;
  27.  
  28.             graphics.beginFill(0x0099cc);
  29.             graphics.drawCircle(0, 0, 10);
  30.             graphics.endFill();
  31.             circle.x = Math.random() * stage.stageWidth;
  32.             circle.y = Math.random() * stage.stageHeight;
  33.  
  34.             addChild(circle);
  35.         }
  36.  
  37.         private function initBox():void {
  38.             _box = new Sprite();
  39.  
  40.             var box:Sprite = _box;
  41.             var graphics:Graphics = box.graphics;
  42.  
  43.             graphics.beginFill(0x0099cc);
  44.             graphics.drawRect(-5, -5, 10, 10);
  45.             graphics.endFill();
  46.             box.x = Math.random() * stage.stageWidth;
  47.             box.y = Math.random() * stage.stageHeight;
  48.  
  49.             addChild(box);
  50.         }
  51.  
  52.         private function initPauseButton():void {
  53.             var button:Button = new Button();
  54.  
  55.             button.label = 'Tweensy.pause()';
  56.             button.addEventListener(MouseEvent.CLICK, onButtonClick);
  57.  
  58.             addChild(button);
  59.         }
  60.  
  61.         private function onButtonClick(e:MouseEvent):void {
  62.             var button:Button = e.currentTarget as Button;
  63.  
  64.             if (Tweensy.paused) {
  65.                 Tweensy.resume();
  66.                 button.label = 'Tweensy.pause()';
  67.             } else {
  68.                 Tweensy.pause();
  69.                 button.label = 'Tweensy.resume()';
  70.             }
  71.         }
  72.  
  73.         private function startCircleTweensy():void {
  74.             var circle:Sprite = _circle;
  75.             var targetCircleX:Number = Math.random() * stage.stageWidth;
  76.             var targetCircleY:Number = Math.random() * stage.stageHeight;
  77.             var targetCircleScale:Number = 1 + Math.random() * 2;
  78.  
  79.             Tweensy.to(circle, { x: targetCircleX, y: targetCircleY, scaleX: targetCircleScale, scaleY: targetCircleScale }, 1, null, 0, null, startCircleTweensy);
  80.         }
  81.  
  82.         private function startBoxTweensy():void {
  83.             var box:Sprite = _box;
  84.             var targetBoxX:Number = Math.random() * stage.stageWidth;
  85.             var targetBoxY:Number = Math.random() * stage.stageHeight;
  86.             var targetBoxScale:Number = 1 + Math.random() * 3;
  87.  
  88.             Tweensy.to(box, { x: targetBoxX, y: targetBoxY, scaleX: targetBoxScale, scaleY: targetBoxScale }, 3, null, 0, null, startBoxTweensy);
  89.         }
  90.  
  91.  
  92.     }
  93.  
  94. }
  95.  
  96.  
  97. import flash.display.Graphics;
  98. import flash.display.Sprite;
  99. import flash.events.MouseEvent;
  100. import flash.filters.BevelFilter;
  101. import flash.text.TextField;
  102. import flash.text.TextFieldAutoSize;
  103. import flash.text.TextFormat;
  104.  
  105. internal class Button extends Sprite {
  106.  
  107.     private var _textField:TextField;
  108.  
  109.     public function get label():String { return _textField.text; }
  110.     public function set label(value:String):void {
  111.         _textField.text = value;
  112.         updateFill();
  113.     }
  114.  
  115.     public function Button() {
  116.         _textField = new TextField();
  117.         _textField.defaultTextFormat = new TextFormat('_等幅', 10, 0x333333, true);
  118.         _textField.autoSize = TextFieldAutoSize.LEFT;
  119.         _textField.x = 8;
  120.         _textField.y = 4;
  121.         addChild(_textField);
  122.  
  123.         filters = [new BevelFilter(1, 45, 0xdddddd, 0xbbbbbb)];
  124.         buttonMode = true;
  125.         mouseChildren = false;
  126.         addEventListener(MouseEvent.MOUSE_UP, onButtonMouseUp);
  127.         addEventListener(MouseEvent.MOUSE_DOWN, onButtonMouseDown);
  128.     }
  129.  
  130.     private function onButtonMouseUp(e:MouseEvent):void {
  131.         var button:Sprite = e.currentTarget as Sprite;
  132.  
  133.         button.filters = null;
  134.         button.filters = [new BevelFilter(1, 45, 0xdddddd, 0xbbbbbb)];
  135.     }
  136.  
  137.     private function onButtonMouseDown(e:MouseEvent):void {
  138.         var button:Sprite = e.currentTarget as Sprite;
  139.  
  140.         button.filters = null;
  141.         button.filters = [new BevelFilter(1, 225, 0xdddddd, 0xbbbbbb)];
  142.     }
  143.  
  144.     private function updateFill():void {
  145.         graphics.clear();
  146.         graphics.beginFill(0xCCCCCC);
  147.         graphics.drawRect(0, 0, _textField.textWidth + 20, _textField.textHeight + 14);
  148.         graphics.endFill();
  149.     }
  150.  
  151. }


About this entry