root/as3/BetweenAS3/trunk/tests/fp10/TweenTest.as

リビジョン 2617, 3.5 kB (コミッタ: yossy, コミット時期: 3 年 前)

BetweenAS3: Changed the timing of calculating tween parameters to the first time of start playing the tween.

Line 
1 /*
2  * BetweenAS3
3  *
4  * Licensed under the MIT License
5  *
6  * Copyright (c) 2009 BeInteractive! (www.be-interactive.org) and
7  *                    Spark project  (www.libspark.org)
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  *
27  */
28 package
29 {
30         import flash.display.MovieClip;
31         import flash.display.Shape;
32         import flash.display.Sprite;
33         import flash.events.Event;
34         import flash.events.MouseEvent;
35         import org.libspark.betweenas3.BetweenAS3;
36         import org.libspark.betweenas3.easing.Cubic;
37         import org.libspark.betweenas3.easing.Exponential;
38         import org.libspark.betweenas3.easing.Linear;
39         import org.libspark.betweenas3.tweens.ITween;
40        
41         /**
42          * @author      yossy:beinteractive
43          */
44         public class TweenTest extends Sprite
45         {
46                 public function TweenTest()
47                 {
48                         addEventListener(Event.ADDED_TO_STAGE, initialize);
49                 }
50                
51                 private function initialize(e:Event):void
52                 {
53                         removeEventListener(Event.ADDED_TO_STAGE, initialize);
54                        
55                         var bg:Shape = new Shape();
56                         bg.graphics.beginFill(0xffffff);
57                         bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
58                         bg.graphics.endFill();
59                         addChild(bg);
60                        
61                         var mc1:MovieClip = new MovieClip();
62                         mc1.graphics.beginFill(0);
63                         mc1.graphics.drawRect(-10, -10, 20, 20);
64                         mc1.graphics.endFill();
65                         addChild(mc1);
66                        
67                         var mc2:MovieClip = new MovieClip();
68                         mc2.graphics.beginFill(0x666666);
69                         mc2.graphics.drawRect(-10, -10, 20, 20);
70                         mc2.graphics.endFill();
71                         addChild(mc2);
72                        
73                         mc1.x = 100;
74                         mc1.y = 100;
75                        
76                         mc2.x = 200;
77                         mc2.y = 100;
78                        
79                         _t = BetweenAS3.parallel(
80                                 BetweenAS3.serial(
81                                         BetweenAS3.tween(mc1, {$x: 100}, null, 1, Exponential.easeIn),
82                                         BetweenAS3.tween(mc1, {$y: 100}, null, 1, Exponential.easeIn),
83                                         BetweenAS3.tween(mc1, {$x: -100}, null, 1, Exponential.easeIn),
84                                         BetweenAS3.tween(mc1, {$y: -100}, null, 1, Exponential.easeIn)
85                                 ),
86                                 BetweenAS3.serial(
87                                         BetweenAS3.tween(mc2, {$x: 100}, null, 1, Cubic.easeOut),
88                                         BetweenAS3.tween(mc2, {$y: 100}, null, 1, Cubic.easeOut),
89                                         BetweenAS3.tween(mc2, {$x: -100}, null, 1, Cubic.easeOut),
90                                         BetweenAS3.tween(mc2, {$y: -100}, null, 1, Cubic.easeOut)
91                                 )
92                         );
93                        
94                         _t.play();
95                        
96                         stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler)
97                 }
98                
99                 private var _t:ITween;
100                
101                 private function mouseDownHandler(e:MouseEvent):void
102                 {
103                         if (_t.isPlaying) {
104                                 _t.stop();
105                         }
106                         else {
107                                 if (_t.position == _t.duration) {
108                                         _t.gotoAndPlay(0);
109                                 }
110                                 else {
111                                         _t.play();
112                                 }
113                         }
114                 }
115         }
116 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。