首页 > 开发 > Flex > 正文

Flex 和JavaScript 交互(带参)

2024-09-12 17:51:10
字体:
来源:转载
供稿:网友
Flex文件:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
width="200" height="150"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.external.*;

[Bindable]
private var jstime: String;

private function init(): void
{
flash.external.ExternalInterface.addCallback("jstest", jstest);
}

public function js() : void {
var m : String = ExternalInterface.call("flashtest","flash");
Alert.show(m);
}


public function jstest(str: String): String
{
jstime = str;
return "jstest::" + jstime;
}

private function ttt(): void
{
Alert.show(jstime);
}
]]>
</mx:Script>
<mx:Button label="test" click="js()" x="142" y="118"/>
<mx:Button label="jstest" click="ttt()" x="76" y="118"/>
<mx:Text x="10" y="43" text="{jstime}" width="180"/>
</mx:Application>

html:
复制代码 代码如下:

<html lang="en">
<SCRIPT language="javascript">
function now()
{
var d=new Date();
return d.getYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
}

function flashtest(sid)
{
return sid + "::" + now();
}


function testflash()
{
var x = flexjs.jstest(now());
alert(x);

}

</SCRIPT>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="flexjs" width="200" height="150"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="flexjs.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="flexjs.swf" quality="high" bgcolor="#869ca7"
width="200" height="150" name="flexjs" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
<br>
<input type="button" value="flashtest" onclick="testflash();">
</html>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表