Flex/Flash 4 ExternalInterface.call - 尝试将字符串从 HTML 获取到 Actionscript [英] Flex/Flash 4 ExternalInterface.call - trying to get a string from HTML to Actionscript

查看:17
本文介绍了Flex/Flash 4 ExternalInterface.call - 尝试将字符串从 HTML 获取到 Actionscript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 HTML 中获取一个字符串并将其放入 Actionscript.

I need to obtain a string from HTML and put it into 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:

the 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 执行命中时

when the javascript execution hits

var label = document.getElementById("username-label");

返回空值并崩溃,没有警报显示没有显示错误消息.我可以通过username-label"(document.getElementById())成功搜索firefox DOM Inspector

a null is returned and crashes, no alert shows no error message is shown. I can successfully do a search firefox DOM Inspector by "username-label" (document.getElementById())

唯一弹出的警告框是动作脚本警告框,内容为空白.

The only alert box that pops up is the action script alert box and the contents are blank.

firfox 3.5 windows,容器是Tomcat.

firfox 3.5 windows, container is Tomcat.

请多多指教,提前致谢.

Please advise, and thank you in advance.

推荐答案

import flash.external.ExternalInterface;
public function getUserName():void{
      var isAvailable:Boolean = ExternalInterface.available;
      //var findUserName:String = "findUserName";
      if(isAvailable){
      ExternalInterface.call("findUserName");
      }
 }

现在创建一个按钮并调用这个函数 getUserName,现在尝试在 JavaScript 中放置一条警报消息,看看它是否会调用.

Now create a button and call this function getUserName and now try to put a alert message in JavaScript and see if that calls.

将方法设为公开,并让我们知道您是否可以调用 JavaScript 方法名称.查看我在你的函数中所做的更改

Make the method Public and let us know whether you are able to call the JavaScript method name. See the changes i made in u r function

注意:Protected 和 Private 也可以使用,这只是为了测试.

Note: Protected and Private will also work, this is just for testing.

更多更新:

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 函数更新到上面并告诉我.

Update your JavaScript function to above and let me know.

谢谢.

这篇关于Flex/Flash 4 ExternalInterface.call - 尝试将字符串从 HTML 获取到 Actionscript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆