root/as3/Embedder/trunk/Embedder/test/Main.as

リビジョン 3032, 6.0 kB (コミッタ: bkzen, コミット時期: 2 年 前)

Embedder ソース+サンプル

Line 
1 package
2 {
3         import flash.display.Bitmap;
4         import flash.display.DisplayObject;
5         import flash.display.MovieClip;
6         import flash.display.Sprite;
7         import flash.events.Event;
8         import flash.events.MouseEvent;
9         import flash.media.Sound;
10         import flash.text.TextField;
11         import flash.text.TextFieldAutoSize;
12        
13         /**
14          * Embedder のテストをするメインクラス。
15          * @author jc at bk-zen.com
16          */
17         public class Main extends Sprite
18         {
19                 private var em: MyEmbedder;
20                 private var btn: Sprite;
21                 private var txt: TextField;
22                 private var btnHandler: Function;
23                 private var canvas:Sprite;
24                
25                 public function Main():void
26                 {
27                         if (stage) init();
28                         else addEventListener(Event.ADDED_TO_STAGE, init);
29                 }
30                
31                 private function init(e:Event = null):void
32                 {
33                         removeEventListener(Event.ADDED_TO_STAGE, init);
34                         // entry point
35                         em = new MyEmbedder();
36                         em.addEventListener(Event.COMPLETE, onComp);
37                 }
38                
39                 private function onComp(e: Event ): void
40                 {
41                         em.removeEventListener(Event.COMPLETE, onComp);
42                         //
43                         addChild(btn = new Sprite());
44                         addChild(canvas = new Sprite());
45                         btn.addChild(txt = new TextField());
46                         txt.autoSize = TextFieldAutoSize.LEFT;
47                         txt.selectable = txt.mouseEnabled = false;
48                         txt.multiline  = btn.buttonMode = true;
49                         makeButton("Embed した画像(GIF, JPG, PNG, SVG)を表示します。", showImages);
50                 }
51                
52                 private function showImages(e: MouseEvent):void
53                 {
54                         makeButton("Embed した画像(GIF, JPG, PNG, SVG)を表示中。\n次 Embed した MP3 を鳴らします。", playSound);
55                         canvas.y = btn.height;
56                         var d: DisplayObject, d2: DisplayObject;
57                         d  = canvas.addChild(em.getBmp(em.Gif));
58                         d2 = canvas.addChild(em.getBmp(em.Jpg));
59                         d2.x = d.width;
60                         d  = canvas.addChild(em.getBmp(em.Png));
61                         d.y = d2.height;
62                         d2 = canvas.addChild(em.getSp(em.Svg));
63                         d2.x = d.width;
64                         d2.y = d.height;
65                 }
66                
67                 private function playSound(e: MouseEvent):void
68                 {
69                         makeButton("Embed した MP3 を鳴らし中。\n次 Embed した SWF (Main が Sprite) を表示します。", showSwf1);
70                         while (canvas.numChildren > 0) { canvas.removeChildAt(0); }
71                         canvas.y = btn.height;
72                         em.getSnd(em.Mp3).play();
73                 }
74                
75                 private function showSwf1(e: MouseEvent): void
76                 {
77                         makeButton("Embed した SWF (Main が Sprite) を表示しています。\n次 Embed した SWF (Main が MovieClip) を表示します。", showSwf2);
78                         while (canvas.numChildren > 0) { canvas.removeChildAt(0); }
79                         canvas.y = btn.height;
80                         canvas.addChild(em.getSp(em.Swf2));
81                 }
82                
83                 private function showSwf2(e: MouseEvent):void
84                 {
85                         makeButton("Embed した SWF (Main が Sprite) を表示しています。\n次 Embed した SWF のリンケージに登録してある Sound を鳴らします。", showSwf3);
86                         while (canvas.numChildren > 0) { canvas.removeChildAt(0); }
87                         canvas.y = btn.height;
88                         var mc: MovieClip = MovieClip(canvas.addChild(em.getMc(em.Swf)));
89                         mc.play();
90                 }
91                
92                 private function showSwf3(e: MouseEvent):void
93                 {
94                         makeButton("Embed した SWF のリンケージに登録してある Sound を鳴らしています。\n次 Embed した SWF のリンケージに登録してある MovieClip を表示します。", showSwf4);
95                         while (canvas.numChildren > 0) { canvas.removeChildAt(0); }
96                         canvas.y = btn.height;
97                         Sound(em.getLib(em.Swf, "puyon")).play();
98                 }
99                
100                 private function showSwf4(e: MouseEvent):void
101                 {
102                         makeButton("Embed した SWF のリンケージに登録してある MovieClip を表示しています。\n次 Embed した SWF のリンケージに登録してある Bitmap を表示します。", showSwf5);
103                         while (canvas.numChildren > 0) { canvas.removeChildAt(0); }
104                         canvas.y = btn.height;
105                         var d: DisplayObject = canvas.addChild(em.getLib(em.Swf, "mc1"));
106                         d.x = d.width;
107                         d.y = d.height;
108                 }
109                
110                 private function showSwf5(e: MouseEvent):void
111                 {
112                         makeButton("Embed した SWF のリンケージに登録してある Bitmap を表示しています。\n次 Embed した XML を表示します。", showSwf6);
113                         while (canvas.numChildren > 0) { canvas.removeChildAt(0); }
114                         canvas.y = btn.height;
115                         canvas.addChild(new Bitmap(em.getLib(em.Swf, "png")));
116                 }
117                
118                 private function showSwf6(e: MouseEvent):void
119                 {
120                         makeButton("Embed した XML を表示します。\n次 別の方法で Embed した XML を表示します。", showSwf7);
121                         while (canvas.numChildren > 0) { canvas.removeChildAt(0); }
122                         canvas.y = btn.height;
123                         var tx: TextField = TextField(canvas.addChild(new TextField()));
124                         tx.width = stage.stageWidth;
125                         tx.height = stage.stageHeight - btn.height;
126                         //
127                         tx.text = "Embed する時に特に mimeType を指定しない場合。";
128                         tx.appendText("\n" + em.getXml(em.Xml).toXMLString());
129                         tx.appendText("\nその時は XML の最初につける。<?xml version=\"1.0\" encoding=\"utf-8\" ?>を省略する。");
130                 }
131                
132                 private function showSwf7(e: MouseEvent):void
133                 {
134                         makeButton("Embed した XML を表示します。", end);
135                         while (canvas.numChildren > 0) { canvas.removeChildAt(0); }
136                         canvas.y = btn.height;
137                         var tx: TextField = TextField(canvas.addChild(new TextField()));
138                         tx.width = stage.stageWidth;
139                         tx.height = stage.stageHeight - btn.height;
140                         //
141                         tx.text = "Embed する時に特に mimeType を指定した場合。";
142                         tx.appendText("\n" + em.getXml(em.Xml).toXMLString());
143                         tx.appendText("\nその時は XML の最初につける。<?xml version=\"1.0\" encoding=\"utf-8\" ?>を省略しない。");
144                 }
145                
146                 private function end(e: MouseEvent):void
147                 {
148                         makeButton("", end);
149                         while (canvas.numChildren > 0) { canvas.removeChildAt(0); }
150                         canvas.y = btn.height;
151                 }
152                
153                 private function makeButton(label: String, eventHandler: Function):void
154                 {
155                         if (btnHandler != null) btn.removeEventListener(MouseEvent.CLICK, btnHandler);
156                         txt.text = label;
157                         btn.graphics.clear();
158                         btn.graphics.beginFill(0xDDDDDD);
159                         btn.graphics.drawRect(0, 0, txt.width, txt.height);
160                         btn.addEventListener(MouseEvent.CLICK, btnHandler = eventHandler);
161                 }
162                
163         }
164        
165 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。