新工作的第一个任务,实现jsp向flex传值.都是从网上参考,实现的,例子如下:
JSP代码:
注意:object中的classid必须要,我开始没有写,在这里耽误好好久.
JS代码:
FLEX代码:
留者自己做纪念
JSP代码:
<head>
<base href="<%=basePath%>">
<script src="testJS.js" language="javascript"></script>
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
<form id="myform" method="post" antion="" name="form1">
name:<input type="text" id="name" name="name1"/>
<input type="submit" value="login" onclick="deliverData();return false"/>
</form>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="flex" width="250" height="100"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="JspToFlex.swf"/>
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="JspToFlex.swf" quality="high" bgcolor="#869ca7"
width="100%" height="100%" name="flex" align="middle"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</body>
注意:object中的classid必须要,我开始没有写,在这里耽误好好久.
JS代码:
function deliverData(){
var flashPlay = document.getElementById("flex");
flashPlay.getData(document.getElementById("name").value);
}
FLEX代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function init():void{
ExternalInterface.addCallback("getData",testFunction);
}
private function testFunction(param:String):void{
text.text = "你输入的是:"+param;
}
protected function btn_clickHandler(event:MouseEvent):void
{
text.text = "重新输入";
}
]]>
</mx:Script>
<mx:TextInput id="text" width="200" height="20" text="12"/>
<mx:Button id="btn" click="btn_clickHandler(event)" label="Click" y="40"/>
</mx:Application>
留者自己做纪念