views:

74

answers:

2

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?

+2  A: 

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
    }
  }    

}
Sinan Taifour
A: 

There is the option of ExternalInterface as the above poster has shown.

If your requirements are a little more complicated then you can use the Adobe provided Flex Ajax Bridge. You'll also need the Flex SDK (see About the Flex Ajax Bridge). The bridge can simplify things if you want to drive most of the SWF behaviour from JavaScript. ExternalInterface is more useful for simple, quick, one-off function calls.

James Fassett