Home | Contact Us | Store

Send HTML Select Menu Value to Flash

This Flash and HTML interactivity example demonstrate how to send value of HTML Pull-down Menu (Select Menu) to Flash Movie. When the Pull-down Menu is selected, the corresponding value of the Menu is sent to Flash at once.

Flash ActionScript and HTML JavaScript communication example display here. Your flash player version is too old to see this flash example!

 

Change color of square box in Flash Movie:

Flash Tutorial Content:

This Flash ActionScript and HTML JavaScript interactivity tutorial show how to interact HTML Pull-down Menu with Flash Movie. The Pull-down Menu is often used in HTML form. This flash example shows how to send the value of Pull-down Menu to Flash.

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:


Step 1:
Layout a Select Menu on the HTML webpage. The JavaScript function changeColor will be executed when the value of Select Menu is changed.

<form action="" id="myform">
Change color of square box in Flash Movie:
<select id="pullDownMenu" onchange="changeColor();">
<option value="1" selected>Red</option>
<option value="2">Green</option>
<option value="3">Blue</option>
<option value="4">Yellow</option>
<option value="5">Black</option>
</select>
</form>

 

Step 2:
Write the JavaScript function changeColor. The JavaScript function will make a call to ActionScript function sendColorToFlash.

 

<script language="JavaScript">
//Get flash movie id (myFlash)
var myFlashMovie;
function init() {
if (document.getElementById) {
myFlashMovie = document.getElementById("myFlash");
}
}

//Wait the page to fully load before initializing
window.onload = init;

 

//This is the function to communicate with Flash
function changeColor() {
if (myFlashMovie) {
//Call the registered ActionScript method (sendColorToFlash)
<!-- access the value of an HTML input by assigning it an id -->
var colorMenu = document.getElementById("pullDownMenu");
var ID = colorMenu.options[colorMenu.selectedIndex].value;
myFlashMovie.sendColorToFlash(ID);
}
}
</script>

 

Flash Side:


Step 1:
Use ExternalInterface.addCallback( ) to register the ActionScript function. Once the ActionScript functions is registered, it can be called by the JavaScript function.

ExternalInterface.addCallback("sendColorToFlash", getColorFromJavaScript);

 

Step 2:
Hook with the ActionScript Function (getColorFromJavaScript)

Download Flash Source File:

Flash Source File Awaiting to be released.

Remarks:

This Flash ActionScript tutorial shows how to send HTML Select Menu value to Flash Movie.

Call Flash ActionScript from HTML JavaScript Call HTML JavaScript from FlashActionScript Float Advertisement Sliding Out