Skip to content

Instantly share code, notes, and snippets.

@tana
Created July 24, 2010 16:05
Show Gist options
  • Save tana/488781 to your computer and use it in GitHub Desktop.
Save tana/488781 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>haXe and Flash ExternalInterface</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("swfobject", "2.2");</script>
<script type="text/javascript">
function incr() {
document["external"].increment();
}
</script>
</head>
<body>
<div id="external">
</div>
<script type="text/javascript">
swfobject.embedSWF("external.swf", "external", "320", "240", "9", false, {}, {"allowScriptAccess": "always"}, {});
</script>
<br />
<button onclick="incr()">+</button>
</body>
</html>
import flash.external.ExternalInterface;
import flash.text.TextField;
class External {
static var tf : TextField;
static var count = 0;
static function main() {
tf = new TextField();
tf.text = Std.string(count);
flash.Lib.current.addChild(tf);
ExternalInterface.addCallback("increment", increment);
}
static function increment() {
count++;
tf.text = Std.string(count);
}
}
コンパイル方法:
haxe -main External -swf9 external.swf
注意:
ローカルで動かす時は、Flashの「グローバルセキュリティ設定パネル」で、external.swfとexternal.htmlがあるディレクトリを常に信頼するようにしておく。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment