send from javascript to actionscript IE problem

2019-08-07 17:51发布

问题:

I tried to send a string from an html page (with javascript) to a swf file (action script 2).

i searched in google, found this page.

but the example code (version 1, not 2, you can find it in the source file .zip) didn't work in IE (IE said: object doesn't support this property or method)

where is the problem? (i don't want to use SWFObject.)

the action script :::

//From Evan Mullins @ circlecube.com
//View post at http://blog.circlecube.com/2008/02/01/actionscript-javascript-communication/



import flash.external.*;

//Set up Javascript to Actioscript
var methodName:String = "sendTextFromHtml";
var instance:Object = null;
var method:Function = recieveTextFromHtml;
var wasSuccessful:Boolean = ExternalInterface.addCallback(methodName, instance, method);

//Actionscript to Javascript
//ExternalInterface.call("recieveTextFromFlash", _root.theText.text);

function recieveTextFromHtml(t) {
    _root.theText.text = t;
}

_root.button.onRelease = function() {
    ExternalInterface.call("recieveTextFromFlash", _root.theText.text);
    _root.theText.text = "";
}

js:::

function recieveTextFromFlash(Txt) {
    document.getElementById('htmlText').value = Txt;
}

and the onclick js code:::

getElementById('flash').sendTextFromHtml(htmlText.value); document.getElementById('htmlText').value = ''

Thank you.

回答1:

give this javascript code a try?

function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName]; 
}  

function addToResults(results) { getFlashMovie("flashdemo").addToResults(results); }