Flex/Flash 4 ExternalInterface.call - trying to get a string from HTML to Actionscript.

Posted by Setori on Stack Overflow See other posts from Stack Overflow or by Setori
Published on 2010-05-18T08:26:46Z Indexed on 2010/05/18 8:30 UTC
Read the original article Hit count: 324

Dear all,

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);
                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.

firfox 3.5 windows, container is Tomcat.

Please advise, and thank you in advance.

© Stack Overflow or respective owner

Related posts about flex

Related posts about flash