開発環境 Apache Flex SDK 4.12.1
FlashDevelop 4.6.2.5
実行環境 Microsoft Windows 8.1 (64bit)
プロジェクトの種類 ActionScript 3/AS3 Project
プロジェクト名 js2flash


参考

Project/Properties
Output
Backgound color #6495ED

Main.as
package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
 
    public class Main extends Sprite 
    {
        private var tf:TextField;
 
        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
 
            tf = new TextField;
            tf.defaultTextFormat = new TextFormat(null, 20, 0xffffff);
            tf.autoSize = TextFieldAutoSize.LEFT;
            tf.text = "ready";
            addChild(tf);
 
            ExternalInterface.addCallback("display", display);
        }
 
        private function display(str:String):void 
        {
            tf.text = str;
        }
 
    }
 
}
 

js2flash.html
<!doctype html>
<head>
<title>js2flash</title>
<script>
function upload()
{
	var element = document.getElementById("data");
	var data = element.value;
//	alert(data);
 
	window.js2flash.display(data);
}
</script>
</head>
 
<body>
<center>
<embed src="js2flash.swf" id="js2flash" width="800" height="600"></embed><br>
<br>
<textarea id="data" cols="80" rows="10">
hello, world
</textarea><br>
<br>
<button onclick="upload()">upload</button>
</center>
</body>
 
最終更新:2014年08月06日 16:33