Search code examples
htmlactionscript-3actionscriptdrop-down-menuflashvars

Dynamically Get a Variable from HTML in Flash/AS3


I have a case where I have a "drop-down box" in an HTML webpage with some JQuery calculations, looks something like this:

<select style="width: 190px;" class="calc" name="os2" id="os2" type="text">
<option value="Front" data-whatever="2">Front </option>
<option value="Front and Back" data-whatever="2.9">Front and Back </option>
</select>

What I'm trying to do is have this Flash ActionScript 3 Application (embedded on the same HTML page) grab a variable from the drop-down box. Now, using FlashVars is fine, except it doesn't account for when the selection is changed (obviously), but...

Is there a way to reload the variable into Flash real-time when the user changes the drop-down box selection?

Any light on this would be terrific, thanks a lot!


Solution

  • You can use ExternalInterface to communicate between Flash and JavaScript.

    This article seems to cover exactly what you want to do:
    Bi-Directional Actionscript/Javascript Communication in AS3

    Bi-directional Actionscript/Javascript communication is something that has been out for a while, but some Flash designers/developers still are saying, "I didn't know you could do that."

    Well you can! And with just a little bit of code.