Flex 和JavaScript 互動(帶參)

來源:互聯網
上載者:User

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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.