主要用到下面两个类
注:调用html页面中的js方法,然后传递多个参数。
AS中的代码
ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript); //注册为可从html页面回调
private function receivedFromJavaScript(value:String):void {
trace("JavaScript says: " + value + "\n");//1000
}
ExternalInterface.call("sendToJavaScript", 100); //调用html 页面中的sendToJavaScript()方法,并且传值为100.
AS项目下的index.template.html(模板配置文件)
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
// For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
var swfVersionStr = "${version_major}.${version_minor}.${version_revision}";
// To use express install, set to playerProductInstall.swf, otherwise the empty string.
var xiSwfUrlStr = "${expressInstallSwf}";
var flashvars = {name:"feng",sex:1,bir:2009-1-1};//往flash中传参数
var params = {};
params.quality = "high";
params.bgcolor = "${bgcolor}";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
var attributes = {};
attributes.id = "${application}";
attributes.name = "${application}";
attributes.align = "middle";
swfobject.embedSWF(
"${swf}.swf?love:"fishing"", "flashContent",
"${width}", "${height}",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
// JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
function sendToActionScript(value) {
swfobject.getObjectById('${swf}').receivedFromJavaScript(1000);
//document.write(jsonString);
//console.log(jsonString)
}
</script>
public function addToStageHandler(event:Event):void
{
var param:Object = root.loaderInfo.parameters;
for(var i:String in param)
{
trace("vars----:"+i,param[i]);
}
}
输出结果如下:vars----:name feng
vars----:sex 1
vars----:bir 2007
vars----:love:fishing