There is a common practice of sending text out from a SWF to JavaScript by using
getURL("JavaScript:myfunction(\""+myVariable+"\"");
and it worked fine for Internet Explorer 5
but there's a strange bug that shows up with Internet Explorer 6 if you use that and try to send out a large string (anything over about 500 characters?). But it is very possible, and not very difficult to send strings of a fairly significant length out to JavaScript from a SWF. Note that this method doesn't work for Netscape 6.0 - 6.1 or ANY version of Internet Explorer on the Macintosh.

THE CODE

//ActionScript.. goes on frame one of the main timeline

smalltext = "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat";

// build the BIGstring by adding a lot of the smalltext strings together
for(i;i<=80;i++){
     BIGstring += ("\n"+i+" \n\n"+smalltext);
}
// set the text in the scrollable area to the newly created BIGstring
scrolltextarea.text = BIGstring;

// when the button is pressed grab the value of the scrollable text area and call
// the JavaScript function that will get the value of the variable b
sendout_btn.onPress = function(){
     b=scrolltextarea.text;
     getURL("JavaScript:getText()");
     stringlength = b.length + " characters in the string";
};


// JavaScript... goes in the HTML page in which the SWF is embedded (see the source for this page if you aren't sure where)

// getText detects whether the client is Netscape or IE and then
// grabs the value of the "b" variable from the SWF and sets the value of the textarea to the value of the "b" variable.
function getText(){
if(window.myFlashmovie) {
var BIGstring = window.document["myFlashmovie"].GetVariable("b");
window.document.form1.Data.value = BIGstring;
}
if(document.myFlashmovie) {
var BIGstring = document.myFlashmovie.GetVariable("b");
document.form1.Data.value = BIGstring;
}
}

Grab the FLA (source) file here

 

last updated 03/20/2006 by mike lyda

 

- 8/25/2003 added the info about this not working on Netscape 6 and IE on Mac. Thanks to S.Waters for bringing that to my attention.
- 3/20/2006 slight changes to get it working in firefox.. gosh this is old..
- 5/30/2006 -- note.. you could be using the Flash / JavaScript Integration Kit or maybe the new External Interface