package { import flash.display.Bitmap; import flash.display.DisplayObject; import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.media.Sound; import flash.text.TextField; import flash.text.TextFieldAutoSize; /** * Embedder のテストをするメインクラス。 * @author jc at bk-zen.com */ public class Main extends Sprite { private var em: MyEmbedder; private var btn: Sprite; private var txt: TextField; private var btnHandler: Function; private var canvas:Sprite; public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); // entry point em = new MyEmbedder(); em.addEventListener(Event.COMPLETE, onComp); } private function onComp(e: Event ): void { em.removeEventListener(Event.COMPLETE, onComp); // addChild(btn = new Sprite()); addChild(canvas = new Sprite()); btn.addChild(txt = new TextField()); txt.autoSize = TextFieldAutoSize.LEFT; txt.selectable = txt.mouseEnabled = false; txt.multiline = btn.buttonMode = true; makeButton("Embed した画像(GIF, JPG, PNG, SVG)を表示します。", showImages); } private function showImages(e: MouseEvent):void { makeButton("Embed した画像(GIF, JPG, PNG, SVG)を表示中。\n次 Embed した MP3 を鳴らします。", playSound); canvas.y = btn.height; var d: DisplayObject, d2: DisplayObject; d = canvas.addChild(em.getBmp(em.Gif)); d2 = canvas.addChild(em.getBmp(em.Jpg)); d2.x = d.width; d = canvas.addChild(em.getBmp(em.Png)); d.y = d2.height; d2 = canvas.addChild(em.getSp(em.Svg)); d2.x = d.width; d2.y = d.height; } private function playSound(e: MouseEvent):void { makeButton("Embed した MP3 を鳴らし中。\n次 Embed した SWF (Main が Sprite) を表示します。", showSwf1); while (canvas.numChildren > 0) { canvas.removeChildAt(0); } canvas.y = btn.height; em.getSnd(em.Mp3).play(); } private function showSwf1(e: MouseEvent): void { makeButton("Embed した SWF (Main が Sprite) を表示しています。\n次 Embed した SWF (Main が MovieClip) を表示します。", showSwf2); while (canvas.numChildren > 0) { canvas.removeChildAt(0); } canvas.y = btn.height; canvas.addChild(em.getSp(em.Swf2)); } private function showSwf2(e: MouseEvent):void { makeButton("Embed した SWF (Main が Sprite) を表示しています。\n次 Embed した SWF のリンケージに登録してある Sound を鳴らします。", showSwf3); while (canvas.numChildren > 0) { canvas.removeChildAt(0); } canvas.y = btn.height; var mc: MovieClip = MovieClip(canvas.addChild(em.getMc(em.Swf))); mc.play(); } private function showSwf3(e: MouseEvent):void { makeButton("Embed した SWF のリンケージに登録してある Sound を鳴らしています。\n次 Embed した SWF のリンケージに登録してある MovieClip を表示します。", showSwf4); while (canvas.numChildren > 0) { canvas.removeChildAt(0); } canvas.y = btn.height; Sound(em.getLib(em.Swf, "puyon")).play(); } private function showSwf4(e: MouseEvent):void { makeButton("Embed した SWF のリンケージに登録してある MovieClip を表示しています。\n次 Embed した SWF のリンケージに登録してある Bitmap を表示します。", showSwf5); while (canvas.numChildren > 0) { canvas.removeChildAt(0); } canvas.y = btn.height; var d: DisplayObject = canvas.addChild(em.getLib(em.Swf, "mc1")); d.x = d.width; d.y = d.height; } private function showSwf5(e: MouseEvent):void { makeButton("Embed した SWF のリンケージに登録してある Bitmap を表示しています。\n次 Embed した XML を表示します。", showSwf6); while (canvas.numChildren > 0) { canvas.removeChildAt(0); } canvas.y = btn.height; canvas.addChild(new Bitmap(em.getLib(em.Swf, "png"))); } private function showSwf6(e: MouseEvent):void { makeButton("Embed した XML を表示します。\n次 別の方法で Embed した XML を表示します。", showSwf7); while (canvas.numChildren > 0) { canvas.removeChildAt(0); } canvas.y = btn.height; var tx: TextField = TextField(canvas.addChild(new TextField())); tx.width = stage.stageWidth; tx.height = stage.stageHeight - btn.height; // tx.text = "Embed する時に特に mimeType を指定しない場合。"; tx.appendText("\n" + em.getXml(em.Xml).toXMLString()); tx.appendText("\nその時は XML の最初につける。を省略する。"); } private function showSwf7(e: MouseEvent):void { makeButton("Embed した XML を表示します。", end); while (canvas.numChildren > 0) { canvas.removeChildAt(0); } canvas.y = btn.height; var tx: TextField = TextField(canvas.addChild(new TextField())); tx.width = stage.stageWidth; tx.height = stage.stageHeight - btn.height; // tx.text = "Embed する時に特に mimeType を指定した場合。"; tx.appendText("\n" + em.getXml(em.Xml).toXMLString()); tx.appendText("\nその時は XML の最初につける。を省略しない。"); } private function end(e: MouseEvent):void { makeButton("", end); while (canvas.numChildren > 0) { canvas.removeChildAt(0); } canvas.y = btn.height; } private function makeButton(label: String, eventHandler: Function):void { if (btnHandler != null) btn.removeEventListener(MouseEvent.CLICK, btnHandler); txt.text = label; btn.graphics.clear(); btn.graphics.beginFill(0xDDDDDD); btn.graphics.drawRect(0, 0, txt.width, txt.height); btn.addEventListener(MouseEvent.CLICK, btnHandler = eventHandler); } } }