TweensyGroup - to
Tweensyで色々なプロパティを動かすんだけど、それらを一括のトゥィーンとして管理したい。そんな時に使うのがTweensyGroupクラス。
下の例では、Spriteを大きくしながら回転させるアニメーションをTweensy.to()とTweensyGroup.to()で動かしてみる。両者とも動きは同じ。Tweensy.to()の場合は、scaleX/scaleYのonUpdate/onCompleteとrotationのonUpdate/onCompleteがそれぞれバラバラにイベント処理される。TweensyGroup.to()の場合はscaleX/scaleY/rotationのonUpdate/onCompleteが一括でイベント処理される。
- ActionScript
- TestTweensy_10.as
- Source
package {
import com.flashdynamix.motion.Tweensy;
import com.flashdynamix.motion.TweensyGroup;
import com.flashdynamix.motion.TweensyTimeline;
import fl.motion.easing.Quadratic;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
[SWF(backgroundColor = 0x000000, width = 600, height = 400, frameRate = 30)]
public class TestTweensy_10 extends Sprite {
private var _boxTweensy:Sprite;
private var _boxTweensyGroup:Sprite;
private var _tweensyTimeline0TextField:TextField;
private var _tweensyTimeline1TextField:TextField;
private var _tweensyGroupTextField:TextField;
public function TestTweensy_10() {
initInstances();
initTextFields();
initButton();
}
private function initInstances():void{
_boxTweensy = createBox();
_boxTweensy.x = 300;
_boxTweensy.y = 100;
addChild(_boxTweensy);
_boxTweensyGroup = createBox();
_boxTweensyGroup.x = 300;
_boxTweensyGroup.y = 300;
addChild(_boxTweensyGroup);
}
private function createBox():Sprite {
var box:Sprite = new Sprite();
var graphics:Graphics = box.graphics;
graphics.beginFill(0x0099cc);
graphics.drawRect(-5, -5, 10, 10);
graphics.endFill();
return box;
}
private function initTextFields():void {
_tweensyTimeline0TextField = createTextField();
_tweensyTimeline0TextField.x = 10;
_tweensyTimeline0TextField.y = 50;
addChild(_tweensyTimeline0TextField);
_tweensyTimeline1TextField = createTextField();
_tweensyTimeline1TextField.x = 10;
_tweensyTimeline1TextField.y = 100;
addChild(_tweensyTimeline1TextField);
_tweensyGroupTextField = createTextField();
_tweensyGroupTextField.x = 10;
_tweensyGroupTextField.y = 250;
addChild(_tweensyGroupTextField);
}
private function createTextField():TextField {
var textField:TextField = new TextField();
var textFormat:TextFormat = new TextFormat('_等幅', 10, 0xffffff);
textField.defaultTextFormat = textFormat;
textField.autoSize = TextFieldAutoSize.LEFT;
return textField;
}
private function initButton():void {
var button:Button = new Button();
button.label = 'start';
button.addEventListener(MouseEvent.CLICK, onButtonClick);
addChild(button);
}
private function onButtonClick(e:MouseEvent):void {
startTweensy();
startTweensyGroup();
}
private function startTweensy():void {
_boxTweensy.scaleX = 1;
_boxTweensy.scaleY = 1;
_boxTweensy.rotation = 0;
_tweensyTimeline0TextField.text = '';
_tweensyTimeline1TextField.text = '';
var tweensyTimeline0:TweensyTimeline = Tweensy.to(_boxTweensy, { scaleX: 5, scaleY: 5 }, 3, Quadratic.easeOut, 1);
var tweensyTimeline1:TweensyTimeline = Tweensy.to(_boxTweensy, { rotation: 90 }, 3, Quadratic.easeOut, 2);
tweensyTimeline0.onUpdate = logTweensyTimeline0;
tweensyTimeline0.onUpdateParams = ['onUpdate'];
tweensyTimeline0.onComplete = logTweensyTimeline0;
tweensyTimeline0.onCompleteParams = ['onComplete'];
tweensyTimeline1.onUpdate = logTweensyTimeline1;
tweensyTimeline1.onUpdateParams = ['onUpdate'];
tweensyTimeline1.onComplete = logTweensyTimeline1;
tweensyTimeline1.onCompleteParams = ['onComplete'];
}
private function startTweensyGroup():void{
_boxTweensyGroup.scaleX = 1;
_boxTweensyGroup.scaleY = 1;
_boxTweensyGroup.rotation = 0;
_tweensyGroupTextField.text = '';
var tweensyGroup:TweensyGroup = new TweensyGroup();
tweensyGroup.to(_boxTweensyGroup, { scaleX: 5, scaleY: 5 }, 3, Quadratic.easeOut, 1);
tweensyGroup.to(_boxTweensyGroup, { rotation: 90 }, 3, Quadratic.easeOut, 2);
tweensyGroup.onUpdate = logTweensyGroup;
tweensyGroup.onUpdateParams = ['onUpdate'];
tweensyGroup.onComplete = logTweensyGroup;
tweensyGroup.onCompleteParams = ['onComplete'];
}
private function logTweensyTimeline0(text:String):void {
text += '\n';
text += 'scaleX = ' + _boxTweensy.scaleX.toString() + '\n';
text += 'scaleY = ' + _boxTweensy.scaleY.toString();
_tweensyTimeline0TextField.text = text;
}
private function logTweensyTimeline1(text:String):void{
text += '\n';
text += 'rotation = ' + _boxTweensy.rotation.toString();
_tweensyTimeline1TextField.text = text;
}
private function logTweensyGroup(text:String):void {
text += '\n';
text += 'scaleX = ' + _boxTweensyGroup.scaleX.toString() + '\n';
text += 'scaleY = ' + _boxTweensyGroup.scaleY.toString() + '\n';
text += 'rotation = ' + _boxTweensyGroup.rotation.toString();
_tweensyGroupTextField.text = text;
}
}
}
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 com.flashdynamix.motion.TweensyGroup;
- import com.flashdynamix.motion.TweensyTimeline;
- import fl.motion.easing.Quadratic;
- import flash.display.Graphics;
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
- [SWF(backgroundColor = 0x000000, width = 600, height = 400, frameRate = 30)]
- public class TestTweensy_10 extends Sprite {
- private var _boxTweensy:Sprite;
- private var _boxTweensyGroup:Sprite;
- private var _tweensyTimeline0TextField:TextField;
- private var _tweensyTimeline1TextField:TextField;
- private var _tweensyGroupTextField:TextField;
- public function TestTweensy_10() {
- initInstances();
- initTextFields();
- initButton();
- }
- private function initInstances():void{
- _boxTweensy = createBox();
- _boxTweensy.x = 300;
- _boxTweensy.y = 100;
- addChild(_boxTweensy);
- _boxTweensyGroup = createBox();
- _boxTweensyGroup.x = 300;
- _boxTweensyGroup.y = 300;
- addChild(_boxTweensyGroup);
- }
- private function createBox():Sprite {
- var box:Sprite = new Sprite();
- var graphics:Graphics = box.graphics;
- graphics.beginFill(0x0099cc);
- graphics.drawRect(-5, -5, 10, 10);
- graphics.endFill();
- return box;
- }
- private function initTextFields():void {
- _tweensyTimeline0TextField = createTextField();
- _tweensyTimeline0TextField.x = 10;
- _tweensyTimeline0TextField.y = 50;
- addChild(_tweensyTimeline0TextField);
- _tweensyTimeline1TextField = createTextField();
- _tweensyTimeline1TextField.x = 10;
- _tweensyTimeline1TextField.y = 100;
- addChild(_tweensyTimeline1TextField);
- _tweensyGroupTextField = createTextField();
- _tweensyGroupTextField.x = 10;
- _tweensyGroupTextField.y = 250;
- addChild(_tweensyGroupTextField);
- }
- private function createTextField():TextField {
- var textField:TextField = new TextField();
- var textFormat:TextFormat = new TextFormat('_等幅', 10, 0xffffff);
- textField.defaultTextFormat = textFormat;
- textField.autoSize = TextFieldAutoSize.LEFT;
- return textField;
- }
- private function initButton():void {
- var button:Button = new Button();
- button.label = 'start';
- button.addEventListener(MouseEvent.CLICK, onButtonClick);
- addChild(button);
- }
- private function onButtonClick(e:MouseEvent):void {
- startTweensy();
- startTweensyGroup();
- }
- private function startTweensy():void {
- _boxTweensy.scaleX = 1;
- _boxTweensy.scaleY = 1;
- _boxTweensy.rotation = 0;
- _tweensyTimeline0TextField.text = '';
- _tweensyTimeline1TextField.text = '';
- var tweensyTimeline0:TweensyTimeline = Tweensy.to(_boxTweensy, { scaleX: 5, scaleY: 5 }, 3, Quadratic.easeOut, 1);
- var tweensyTimeline1:TweensyTimeline = Tweensy.to(_boxTweensy, { rotation: 90 }, 3, Quadratic.easeOut, 2);
- tweensyTimeline0.onUpdate = logTweensyTimeline0;
- tweensyTimeline0.onUpdateParams = ['onUpdate'];
- tweensyTimeline0.onComplete = logTweensyTimeline0;
- tweensyTimeline0.onCompleteParams = ['onComplete'];
- tweensyTimeline1.onUpdate = logTweensyTimeline1;
- tweensyTimeline1.onUpdateParams = ['onUpdate'];
- tweensyTimeline1.onComplete = logTweensyTimeline1;
- tweensyTimeline1.onCompleteParams = ['onComplete'];
- }
- private function startTweensyGroup():void{
- _boxTweensyGroup.scaleX = 1;
- _boxTweensyGroup.scaleY = 1;
- _boxTweensyGroup.rotation = 0;
- _tweensyGroupTextField.text = '';
- var tweensyGroup:TweensyGroup = new TweensyGroup();
- tweensyGroup.to(_boxTweensyGroup, { scaleX: 5, scaleY: 5 }, 3, Quadratic.easeOut, 1);
- tweensyGroup.to(_boxTweensyGroup, { rotation: 90 }, 3, Quadratic.easeOut, 2);
- tweensyGroup.onUpdate = logTweensyGroup;
- tweensyGroup.onUpdateParams = ['onUpdate'];
- tweensyGroup.onComplete = logTweensyGroup;
- tweensyGroup.onCompleteParams = ['onComplete'];
- }
- private function logTweensyTimeline0(text:String):void {
- text += '\n';
- text += 'scaleX = ' + _boxTweensy.scaleX.toString() + '\n';
- text += 'scaleY = ' + _boxTweensy.scaleY.toString();
- _tweensyTimeline0TextField.text = text;
- }
- private function logTweensyTimeline1(text:String):void{
- text += '\n';
- text += 'rotation = ' + _boxTweensy.rotation.toString();
- _tweensyTimeline1TextField.text = text;
- }
- private function logTweensyGroup(text:String):void {
- text += '\n';
- text += 'scaleX = ' + _boxTweensyGroup.scaleX.toString() + '\n';
- text += 'scaleY = ' + _boxTweensyGroup.scaleY.toString() + '\n';
- text += 'rotation = ' + _boxTweensyGroup.rotation.toString();
- _tweensyGroupTextField.text = text;
- }
- }
- }
- 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 “TweensyGroup - to,” an entry on jp.ferv.blog
- Published:
- Tue, May 19th, 2009 at 1:29 AM
- Author:
- dsk
- Category:
- Web
- Tags:
- ActionScript 3.0, Tweensy
No comments
Jump to comment form | comments rss | trackback uri