How to Use Java Script in Flash 8
One of the common ways that JavaScript can be used inside Flash 8 is via the command "fscommand". There are however many other tools that have been developed that allow Flash and JavaScript developers to use both languages on the same platform. One of these is the Flash/ JavaScript Integration Kit that handles communication between the 2 technologies.
These technologies make it easier to implement the integration of the 2 languages in a more powerful and stable way. The use of what is called the External Interface allows developers to integrate, implement and offer support for Flash and JavaScript while allowing for synchronous communication.
Instructions
-
Using "fscommand"
-
1
Fire up your Flash 8 application and create a new document.
-
2
Create a button symbol inside the flash page.
-
-
3
Convert the button symbol into a button by pressing F8 and selecting "button."
-
4
Click on the button symbol and press F9 to bring up the "Actions" panel. This is where the code that activates the button will placed.
-
5
Copy and paste the code below inside the Actions panel:
on(release){
fscommand( "Live", "We are live and loaded");
}The command above allows flash to communicate with the parent HTML document that it is running from by calling a JavaScript function that lets it, in this case, display a message box with the message "We are live and loaded".
-
6
Place the following lines of code inside the parent HTML page from which the above flash application will be running:
<SCRIPT LANGUAGE = "JavaScript">
<!--
function Live_DoFSCommand (command, args) {
if (command = = "Live") {
alert(args);
}
} -
7
Test the movie by choosing "file" "Publish Preview" "HTML". Be sure to add the JavaScript code once you publish to allow flash to communicate with the HTML page.
External Interfacing
-
8
Create a function in your HTML page using the format below:
<script language = "JavaScript">
function Live() {
return window.location.toString();
}
</script>The above function returns the URL of the requested page.
-
9
Fire up your Flash 8 application and create a new page.
-
10
Create a button symbol and press F9 to convert to a button.
-
11
Select button and name it appropriately.
-
12
Select the button instance on stage and press F9 to bring up the "Actions" panel.
-
13
Copy and paste the code below inside the "Actions" panel:
Import.flash.external.ExternalInterface;
Function displayWebsite(): Void {
locationDisplay.text = ExternalInterface.call ("Live");
}
locationButton.addEventListener ("click", mx.utils.Delegate.create (this, displayWebsite ) );
-
1
Tips & Warnings
The syntax for the fscommand in flash is:
on(release){
fscommand( "DoSomething", arguments);
}
The fscommand can carry extra parameters as shown below:
Fscommand ("Live", "Hello, " +name + ", Welcome to eHow!")
References
Resources
- Photo Credit movie reel image by Maria Bell from Fotolia.com