flash文件与面页交互:
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>