Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 512

Programming actionscript 3.0
Table of Contents

Advertisement

Calling ActionScript code from JavaScript
Communication is supposed to be a two-way street, and the Introvert IM application is no
exception. Not only does the Flash Player IM client call JavaScript to send messages, but the
HTML form calls JavaScript code to send messages to and ask for information from the SWF
file as well. For example, when the SWF file notifies the container that it has finished
establishing contact and it's ready to communicate, the first thing the browser does is call the
IMManager class's
getStatus()
SWF IM client. This is done in the web page, in the
<script language="JavaScript">
...
function updateStatus()
{
if (swfReady)
{
var currentStatus = getSWF("IntrovertIMApp").getStatus();
document.forms["imForm"].status.value = currentStatus;
}
}
...
</script>
The code checks the value of the
notified the browser that it has registered its methods with the ExternalInterface class. If the
SWF file is ready to receive communication, the next line (
calls the
getStatus()
code:
The
JavaScript function is called, returning a reference to the JavaScript object
getSWF()
representing the SWF file. The parameter passed to
object is returned in case there is more than one SWF file in an HTML page. The value
passed to that parameter must match the
attribute of the
<embed>
Using the reference to the SWF file, the
method of the SWF object. In this case the function name "
that's the name under which the ActionScript function is registered using
ExternalInterface.addCallback()
512
Using the External API
method to retrieve the initial user availability status from the
swfReady
method in the IMManager class. Three things happen in this line of
tag used to embed the SWF file.
.
updateStatus()
variable, which tracks whether the SWF file has
var currentStatus =
getSWF()
attribute of the
id
<object>
method is called as though it's a
getStatus()
getStatus
function, as follows:
...) actually
determines which browser
tag and
name
" is used because

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents