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

查看:283
本文介绍了Flex / Flash 4 ExternalInterface.call - 尝试从HTML到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:

 函数findUserName(){
var label = document.getElementById(username-label);
if(label.value!=){
alert(框中的名字是:+ label.value);
return label.value;}
else
returntextbox中没有东西;}}

JSP:

 <%IUserSession userSession = SessionManager.getSession();%> 

< logic:notEmpty name =userSession>
< logic:notEqual value =anonymousname =userSessionproperty =userLoginId>
< td align =rightwidth =10%>
< input id =username-labeltype =textvalue =< bean:write name =userSessionproperty =userLoginId/> />
< / td>
< /逻辑:notEqual>
< /逻辑:notEmpty>

呈现的HTML:

 < td align =rightwidth =10%> 
< input id =username-labeltype =textvalue =a-valid-username/>
< / td>

当javascript执行命中时

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

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

弹出的唯一警报框是动作脚本提醒框和内容是空的。

firfox 3.5 windows,容器是Tomcat。



请指教,并提前致谢。

解决方案

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






$现在创建一个按钮并调用这个函数getUserName,现在尝试在JavaScript中添加一条警告消息,看看是否有这个调用。



使方法成为Public,让我们知道您是否能够调用JavaScript方法名称。看看我在你的函数中所做的修改注意:保护和私人也将工作,这只是为了测试。



更多更新:

$ p $ 函数findUserName(){
//我们正在初始检查自己。
if(!document.getElementById)return;
var label = document.getElementById(username-label);
alert(label);
if(label.value!=){
alert(框中的名字是:+ label.value);
return label.value;}
else
returntextbox中没有东西;}}

更新您的JavaScript功能到上面,让我知道。



谢谢。


I need to obtain a string from HTML and put it into Actionscript.

the 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);}}

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";}}

the 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>

the rendered HTML:

<td align="right" width="10%">
    <input id="username-label" type="text" value="a-valid-username" />
</td>

when the javascript execution hits

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

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, 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");
      }
 }

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

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

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

More Update:

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";}}

Update your JavaScript function to above and let me know.

Thanks.

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

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