Technology Programming

How to Use Javascript With Flash

    • 1). Set the following parameter between the "object" tags in the embed code of your HTML document:

      <param name="allowScriptAccess" value="always" />

      This will ensure that your Flash movie will be permitted to communicate with Javascript while you test it locally (see References 1, page 2). When you publish, you may change the value to "sameDomain" to prevent malicious use of your SWF file by third-party websites.

    • 2). Include the ExternalInterface class in the Actionscript code of your Flash file with the following command:

      import flash.external.*;

      (see References 1, page 5).

    • 3). Write a Javascript function in your HTML document that takes at least one argument and returns a value. You will not need to write any special Javascript code to call this function from Flash 8.

    • 4). Use the ExternalInterface.call() method in your Actionscript to call your Javascript function from the embedded Flash movie. The first parameter of this method is the Javascript function's name as a string, and you can follow it with as many parameters as you want to pass outside to the function, all separated by commas. A general form of this call is:

      ExternalInterface.call(FunctionName, Parameter1, Parameter2, ... )

      (see References 1, page 5).

    • 5). Use a normal variable assignment operator in your Actionscript code to retrieve the return value from the Javascript function, just as you would with any function:

      ReturnedValue = ExternalInterface.call(FunctionName, Parameter1, Parameter2, ... );

    • 6). Use Actionscript's typecasting methods on the ExternalInterface call if you run into problems with the type of value Javascript returns. Int() and String() are typical examples (see References 2).

    • 7). Use the addCallback() method of the ExternalInterface class to make methods in your Actionscript accessible to external Javascripts (see References 1, page 6). The addCallback() method has the following general form:

      ExternalInterface.addCallback(ExternalName, Instance, InternalName)

      ExternalName is the name by which the function may be called from Javascript, and InternalName is the name of the function in Actionscript. The "Instance" parameter is used to specify the resolution of the "this" keyword, and is usually set to "null".

    • 8). Call your Actionscript function from Javascript using the name you specified for "ExternalName" in the addCallback method, preceeded by a valid DOM reference to the Flash movie. For example:

      window.document.flashMovie.flashFunctionName(Parameter1, Parameter2, ... );

      See the Resources section for a more in-depth discussion of valid DOM references, and be sure to test your code in multiple browsers to ensure the Flash movie is referenced correctly.

SHARE
RELATED POSTS on "Technology"
Blitzerwarner: Could You Escape the Speed Cameras?
Blitzerwarner: Could You Escape the Speed Cameras?
What Makes a Perfect Web Design Company?
What Makes a Perfect Web Design Company?
Inside No-Fuss Products In Gaming Computers
Inside No-Fuss Products In Gaming Computers
Gaming Institute, Game Design Schools at PAI-ILS, PAI International Learning Solutions Pune
Gaming Institute, Game Design Schools at PAI-ILS, PAI International Learning Solutions Pune
Free Music Players For Websites
Free Music Players For Websites
'See How NCP Tracks Down Fake Ration Card Holders'
'See How NCP Tracks Down Fake Ration Card Holders'
You Can Stop Panic Attacks in Just two Minutes
You Can Stop Panic Attacks in Just two Minutes
WordPress Blog to WP Site! A Journey to Online Success
WordPress Blog to WP Site! A Journey to Online Success
Videos will give your business portal an extra leverage
Videos will give your business portal an extra leverage
Excellent Ways To Make Weight Loss Work For You
Excellent Ways To Make Weight Loss Work For You
Five Notable Differences between National and International Logo Designs
Five Notable Differences between National and International Logo Designs
Who Should Your Phoenix Web Design Client Be?
Who Should Your Phoenix Web Design Client Be?
White Papers & Other Documents - including ALFLB
White Papers & Other Documents - including ALFLB
Google Analytics Tips
Google Analytics Tips
Want To Make Your Website Faster? Follow These Steps
Want To Make Your Website Faster? Follow These Steps
The Starting of Couture Apparel
The Starting of Couture Apparel
Choose Custom Website Design Services
Choose Custom Website Design Services
Choosing the Right Joomla CMS Developer
Choosing the Right Joomla CMS Developer
A Look at SQL Server Denali AlwaysOn
A Look at SQL Server Denali AlwaysOn
4 Tips to Choose the Perfect Flash Animation Course
4 Tips to Choose the Perfect Flash Animation Course

Leave Your Reply

*