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

リビジョン 3019, 2.9 kB (コミッタ: yossy, コミット時期: 4 年 前)

BetweenAS3: Merged "Dramatic Before After" branch to trunk.

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.Shape;
31         import flash.display.Sprite;
32         import flash.events.Event;
33         import flash.events.MouseEvent;
34         import org.libspark.betweenas3.BetweenAS3;
35         import org.libspark.betweenas3.easing.Back;
36         import org.libspark.betweenas3.tweens.ITween;
37        
38         /**
39          * @author      yossy:beinteractive
40          */
41         public class FunctionActionTweenTest extends Sprite
42         {
43                 public function FunctionActionTweenTest()
44                 {
45                         addEventListener(Event.ADDED_TO_STAGE, initialize);
46                 }
47                
48                 private function initialize(e:Event):void
49                 {
50                         removeEventListener(Event.ADDED_TO_STAGE, initialize);
51                        
52                         setupBackground();
53                        
54                         var box:Box = addChild(new Box()) as Box;
55                        
56                         box.y = 300;
57                        
58                         _t = BetweenAS3.serial(
59                                 BetweenAS3.func(trace, ['Start!']),
60                                 BetweenAS3.tween(box, {x: 700}, {x: 100}, 1.2, Back.easeInOut),
61                                 BetweenAS3.func(trace, ['Complete!'])
62                         );
63                        
64                         _t.play();
65                        
66                         stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler)
67                 }
68                
69                 private var _t:ITween;
70                
71                 private function setupBackground():void
72                 {
73                         var bg:Shape = new Shape();
74                         bg.graphics.beginFill(0xffffff);
75                         bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
76                         bg.graphics.endFill();
77                         addChild(bg);
78                 }
79                
80                 private function mouseDownHandler(e:MouseEvent):void
81                 {
82                         if (_t.isPlaying) {
83                                 _t.stop();
84                         }
85                         else {
86                                 if (_t.position == _t.duration) {
87                                         _t.gotoAndPlay(0);
88                                 }
89                                 else {
90                                         _t.play();
91                                 }
92                         }
93                 }
94         }
95 }
96
97 import flash.display.Shape;
98
99 internal class Box extends Shape
100 {
101         public function Box()
102         {
103                 graphics.beginFill(0x000000);
104                 graphics.drawRect(-10, -10, 20, 20);
105                 graphics.endFill();
106         }
107 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。