Call Flash ActionScript from JavaScript HTML Button
This Flash and HTML interactivity example demonstrate how to use HTML Button with JavaScript functions to call ActionScript functions in Flash Movie. This is very easy to call the Actionscript in Flash with HTML button hook with JavaScript Functions.
| HTML Button Interact with Flash Movie: |
Flash Tutorial Content:
This Flash ActionScript and HTML JavaScript interactivity tutorial shows how to create communication between HTML JavaScript and Flash ActionScript. It shows how to call the Flash ActionScript from two HTML buttons. The JavaScript Functions will be executed when the buttons are clicked. Then the JavaScript Functions will in turn make a call to the responsible ActionScripts of the Flash Movie.
The completed Flash Movie of this tutorial is shown as above. You may play around to see how it works.
Flash ActionScript and HTML Codes:
HTML Webpage Side:
Layout two buttons on the HTML webpage. The JavaScript functions will be executed when the buttons are clicked.
<input type="button" value="Display Message in Flash Movie"
onClick="document.getElementById('FlashID').runActionScript_1()">
<input type="button" value="Remove Message in Flash Movie"
onClick="document.getElementById('FlashID').runActionScript_2()">
Flash Side:
Step 1:
Use ExternalInterface.addCallback( ) to register the two ActionScript functions. Once the ActionScript functions are registered, they can be called by the JavaScript functions.
ExternalInterface.addCallback("runActionScript_1", asScriptFunction_1);
ExternalInterface.addCallback("runActionScript_1", asScriptFunction_2);
Step 2:
Hook with the ActionScript Functions
function asScriptFunction_1():void {
-- Print out text message
}
function asScriptFunction_2():void {
-- Remove text message
}
Download Flash Source File:
Awaiting to be released.
Remarks:
This Flash ActionScript tutorial shows how to call Flash ActionScript from HTML button with JavaScript.