Javascript – How to update the text in a loaded SWF file with javascript/AS3

actionscript-3flashjavascriptjquery

I need to build a live preview in Flash which will show a user a customised version of a product – for example with their own text on the site. I don't use Flash normally but understand a little bit of Actionscript 3.

I am using jQuery to embed and communicate with my SWF. I have a SWF movie to which I am passing an initial value via a Flashvar and this shows up with the custom text in my movie. (I create the text field in the movie with Actionscript 3)

How can I then use javascript to later send updated values for my Flashvars to the movie – for example when the customer changes the text in an input field on the HTML page?

Best Answer

You will need to define your own function to change the textbox, and make it available to your javascript by using ExternalInterface.

It goes something like this:

class MyClass {

  static function main() {      
    if (flash.external.ExternalInterface.available) {
      flash.external.ExternalInterface.addCallback("updateText", updateText);
    }

    static function updateText(txt) {
      // Whatever you want
    }
  }    

}