ExternalInterface.call() not getting return value

后端 未结 7 1888
鱼传尺愫
鱼传尺愫 2021-01-12 23:39

I have a Javascript function that returns the innerHTML of a div. I am attempting to call this function from Actionscript and store the return value. I know that the Java

相关标签:
7条回答
  • 2021-01-12 23:53

    Try to get the object back from your external interface call without casting it first, and take a look at it in the debugger. If it is not a string, trying to cast it to a string will result in null. This should be a string, but it doesn't hurt to see what you are actually getting back before you try to work with it.

    0 讨论(0)
  • 2021-01-12 23:58

    You should use the import statement

    import flash.external.*;
    
    0 讨论(0)
  • 2021-01-13 00:01

    I also noticed you got a typo in your code => textField != textfield

    0 讨论(0)
  • 2021-01-13 00:02

    It seems to me that your problem is that from javascript you are returning a string, the innerHTML property of your myDiv element. In actionscript you have datatyped the variable that the ExternalInterface call returns to as an Object, but it is a String. Maybe you have already caught this, but I can't tell as you haven't amended your code.

    //The following is an Object
    var x = document.getElementById("myDiv");
    
    /*
    You are returning the innerHTML property of x, a string, but on the
    flash end your expecting an object in your actionscript.
    */
    return x.innerHTML;
    
    //The following seems incorrect to me.
    var retData:Object = ExternalInterface.call("JSFunc");
    
    //Should be
    var retData:String = ExternalInterface.call("JSFunc");
    

    Hope this was helpful, take care.

    0 讨论(0)
  • 2021-01-13 00:04

    This is a working sample based on the code you provided. You can right click it to view the source. I suspect the problem lies in the HTML for 'myDiv' or when you are making the actionscript call.

    0 讨论(0)
  • 2021-01-13 00:07

    The source of the problem that I have been having has to do the object tag that I was using to embed the flash movie. I was using a tag that followed this example http://www.w3schools.com/flash/flash_inhtml.asp, I changed it to match this example: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_4150 and then I made sure that I added id to the object and everything worked.

    0 讨论(0)
提交回复
热议问题