[AS3]JS和flash的通信代码示例
[AS3]JS和flash的通信代码示例
AS部分
- flash代码:ExternalInterface.addCallback("abcd", yun);
- function yun(zi:String):void{
- txt.text = zi;
- }
HTML部分
- <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
- <head>
- <title></title>
- <meta name="google" value="notranslate" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <style type="text/css" media="screen">
- html, body { height:100%; }
- body { margin:0; padding:0; overflow:auto; text-align:center;
- background-color: #999999; }
- object:focus { outline:none; }
- #flashContent { display:none; }
- </style>
- <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 = "10.2.0";
- // To use express install, set to playerProductInstall.swf, otherwise the empty string.
- var xiSwfUrlStr = "playerProductInstall.swf";
- var flashvars = {};
- var params = {};
- params.quality = "high";
- params.bgcolor = "#999999";
- params.allowscriptaccess = "sameDomain";
- params.allowfullscreen = "true";
- var attributes = {};
- attributes.id = "test86";
- attributes.name = "test86";
- attributes.align = "middle";
- swfobject.embedSWF(
- "test86.swf", "flashContent",
- "800", "600",
- 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 testJSTO()
- {
- sendToActionScript("js调用AS3代码!!");
- }
- function sendToActionScript(value) {
- var a = document.getElementById("test86");
- if(a){
- alert(a.id);
- alert(value);
- a.abcd(value);
- }
- }
- </script>
- </head>
- <body>
- <button id = "button" type="button" onClick = "testJSTO();">Click Me!</button>
- <div id="flashContent">
- <p>
- To view this page ensure that Adobe Flash Player version
- .2.0 or greater is installed.
- </p>
- <script type="text/javascript">
- var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
- document.write("<a href='http://www.adobe.com/go/getflashplayer'><img src='"
- + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>" );
- </script>
- </div>
- </body>
- </html>
注意文件还有swfobject.js.刚试了下不发布直接点击html 这样反复测试是不行的,会因为安全沙箱的问题不能访问.放进apache里,通过
http://127.0.0.1:8088/test.html 就可以测试了。
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...