我需要从HTML中获取一个字符串,并将其放入Actionscript中。
actionscript:
import flash.external.ExternalInterface;
protected function getUserName():void{
var isAvailable:Boolean = ExternalInterface.available;
var findUserName:String = "findUserName";
if(isAvailable){
var foundUserName:String = ExternalInterface.call(findUserName).toString();
Alert.show(foundUserName);}}javascript:
function findUserName() {
var label = document.getElementById("username-label");
if(label.value != ""){
alert("the name in the box is: " + label.value);
return label.value;}
else
return "nothing in the textbox";}}JSP:
<%IUserSession userSession = SessionManager.getSession();%>
<logic:notEmpty name="userSession">
<logic:notEqual value="anonymous" name="userSession" property="userLoginId">
<td align="right" width="10%" >
<input id="username-label" type="text" value="<bean:write name="userSession" property="userLoginId"/>" />
</td>
</logic:notEqual>
</logic:notEmpty>呈现的HTML:
<td align="right" width="10%">
<input id="username-label" type="text" value="a-valid-username" />
</td>当javascript执行命中
var label = document.getElementById("username-label");返回一个null并崩溃,没有警报显示没有显示错误消息。我可以通过“用户名标签”(document.getElementById())成功地搜索firefox检查器。
弹出的唯一警报框是动作脚本警告框,内容为空。
第一福克斯3.5窗口,容器是Tomcat。
请事先提出建议,谢谢。
发布于 2010-05-18 14:19:08
import flash.external.ExternalInterface;
public function getUserName():void{
var isAvailable:Boolean = ExternalInterface.available;
//var findUserName:String = "findUserName";
if(isAvailable){
ExternalInterface.call("findUserName");
}
}现在创建一个按钮并调用这个函数getUserName,现在尝试在JavaScript中放置一条警告消息,看看是否调用。
将方法公之于众,并让我们知道您是否能够调用JavaScript方法名。请参阅我在u_r函数中所做的更改。
备注:受保护和私有也会起作用,这只是为了测试。
更多更新:
function findUserName() {
// We are checking down initially itself.
if (!document.getElementById) return;
var label = document.getElementById(username-label);
alert(label);
if(label.value != ""){
alert("the name in the box is: " + label.value);
return label.value;}
else
return "nothing in the textbox";}}将您的JavaScript函数更新到上面,并通知我。
谢谢。
https://stackoverflow.com/questions/2855599
复制相似问题