0

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.

Setori
  • 9,286
  • 11
  • 38
  • 45

1 Answers1

0
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.

Thalaivar
  • 20,946
  • 5
  • 57
  • 67
  • * I have made it public, though it still works with protected (as you noted). * I have removed everything in the javascript message except alert("javascript land"); and the alert successfully fires. Only as soon as I do a document.getElementsById("username-label"); it bombs with a null and any other alert afterwards or before do not fire. * also redid the actionscript String "findUserName" this predictably had no impact. * I already have a button attached to findUserName. So I can get into javascript land but from there.... – Setori May 19 '10 at 02:14
  • Did you try to see in firebug or through an alert whether the value you are getting in javascript is not null. I think you are checking it, just cross checking on this. – Thalaivar May 19 '10 at 06:13
  • the database just went down, the db team are at it right now - and im ITCHING to get at this: I notice you did this "getElementById(username-label);" the username-label has no "". I bet this works... get right back to you. – Setori May 20 '10 at 10:45
  • Sorry in reply to the previous comment - yes I did firebug it and the value was only null - (well cross checked) --- you can see im fiddling my fingers waiting for this db to come back online – Setori May 20 '10 at 10:48
  • Okay I tried "getElementById(username-label);" without the "" and it hangs on that statement. I tried it with single quotes ' ' and it returns a null. the alert displays the word null. The if statement afterwards does not get hit and it hangs. – Setori May 24 '10 at 02:12
  • At least I can return a string: so if I only include a return "string"; then the action script displays the pop up correctly. – Setori May 24 '10 at 02:20
  • might be the issue http://stackoverflow.com/questions/2632137/severe-issues-with-document-getelementbyid – Setori May 24 '10 at 02:24
  • I used Hexagon Theory's answer to solve it :) http://stackoverflow.com/questions/536538/pass-value-to-iframe-from-a-window – Setori May 24 '10 at 06:59
  • The problem was: the documnet was the flash container html page and not the whole html page. So the username value was not actually in the document. therefore a null was returned. – Setori May 24 '10 at 07:01