在Flex开发的时候,经常遇到一些问题处理起来比较麻烦.这个时候调用html页面里的js代码就成了最快的解决方案.flex主要是通过ExternalInterface.call来调用页面的代码,下面的例子是不需要返回值的调用.
joinmeet.mxml
[code]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="200" height="150">
<mx:Script>
<![CDATA[
import flash.external.*;
public function Joinmeet() : void {
var f : String = "showsubmenu";
var m : String = ExternalInterface.call(f,"0");
trace(m);
}
public function callWrapper():void {
var f:String = "changeDocumentTitle";
var m:String = ExternalInterface.call(f,"New Title");
trace(m);
}
]]>
</mx:Script>
<mx:Button label="提交" click="Joinmeet()" x="123" y="118"/>
</mx:Application>
[/code]
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style type="text/css">
<!--
.Layer1 {
position:absolute;
left:0px;
top:50px;
width:80%;
height:205px;
z-index:1;
background:#ffe;
border:1px #999 solid;
background:#000;
}
#Layer1 {
position:absolute;
left:15px;
top:3px;
width:74px;
height:26px;
z-index:2;
background:#f00;
}
-->
</style>
<SCRIPT language="javascript">
function showsubmenu(sid)
{
whichEl = eval("submenu" + sid);
if (whichEl.style.display == "none")
{
eval("submenu" + sid + ".style.display=\"\";");
}
else
{
eval("submenu" + sid + ".style.display=\"none\";");
}
}
function changeDocumentTitle(a) {
window.document.title=a;
return "successful";
}
</SCRIPT>
<div id="Layer1" οnclick="showsubmenu(0)" ></div>
<div class="Layer1" id=submenu0 align="center" style="display:none;">
<object id="joinmeet" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="200" height="150" allowScriptAccess='always'>
<param name='flashvars' value=''>
<param name='src' value='joinmeet.swf'>
<embed src="joinmeet.swf" name="joinmeet.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" width="200" height="150" name="joinmeet" flashvars="" allowScriptAccess='always'></embed>
</object>
</div>
<body>
</body>
</html>
[/code]
joinmeet.mxml
[code]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="200" height="150">
<mx:Script>
<![CDATA[
import flash.external.*;
public function Joinmeet() : void {
var f : String = "showsubmenu";
var m : String = ExternalInterface.call(f,"0");
trace(m);
}
public function callWrapper():void {
var f:String = "changeDocumentTitle";
var m:String = ExternalInterface.call(f,"New Title");
trace(m);
}
]]>
</mx:Script>
<mx:Button label="提交" click="Joinmeet()" x="123" y="118"/>
</mx:Application>
[/code]
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style type="text/css">
<!--
.Layer1 {
position:absolute;
left:0px;
top:50px;
width:80%;
height:205px;
z-index:1;
background:#ffe;
border:1px #999 solid;
background:#000;
}
#Layer1 {
position:absolute;
left:15px;
top:3px;
width:74px;
height:26px;
z-index:2;
background:#f00;
}
-->
</style>
<SCRIPT language="javascript">
function showsubmenu(sid)
{
whichEl = eval("submenu" + sid);
if (whichEl.style.display == "none")
{
eval("submenu" + sid + ".style.display=\"\";");
}
else
{
eval("submenu" + sid + ".style.display=\"none\";");
}
}
function changeDocumentTitle(a) {
window.document.title=a;
return "successful";
}
</SCRIPT>
<div id="Layer1" οnclick="showsubmenu(0)" ></div>
<div class="Layer1" id=submenu0 align="center" style="display:none;">
<object id="joinmeet" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="200" height="150" allowScriptAccess='always'>
<param name='flashvars' value=''>
<param name='src' value='joinmeet.swf'>
<embed src="joinmeet.swf" name="joinmeet.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" width="200" height="150" name="joinmeet" flashvars="" allowScriptAccess='always'></embed>
</object>
</div>
<body>
</body>
</html>
[/code]