How to Send Information as Functions From AS3

Sending information as functions allows more Flash and web design flexibility. Functions let web page buttons interact with objects on a Flash stage. Besides saving Flash screen space, button-free Flash programs, when used with a standardized web flash button interface, will eliminate the need to code buttons into your flash program. With a standardized web-button flash interface you will also be able to adapt a standard format that site contributors can design Flash programs for.

Things You'll Need

  • Adobe Flash Professional (versions CS3, CS4, or CS5)
Show More

Instructions

    • 1

      Create an ActionScript 3 (AS3) file with Adobe Flash Professional. The file will contain the Javascript calling functions and generate and contain the Javascript function parameters. Create an HTML file to contain HTML form code, and a JavaScript module that contains the ActionScript calling statement, and generate and store the ActionScript function parameters.

    • 2

      Write the code in the AS3 file to create a button on the Flash stage. Include in the code an event listener that calls a AS3 function within the AS3 file that will send information variables to the JavaScript script in the HTML file when the button is clicked. Use the "ExternalInterface.call" method to call the JavaScript function from the AS3 file. Specify the parameters in the call method to include the web file address of the HTML file, the function name of the function used in the JavaScript script, and the AS3 information variable or variables to be sent to the JavaScript function.

    • 3

      Register the AS3 function that will be called from the JavaScript with the "ExternalInterface.addCallback()" method in the AS3 file. Specify the actual name of the AS3 function to be called from the JavaScript function as the first parameter in this method. Specify the second parameter as the function name that the JavaScript will use to call the AS3 function.

    • 4

      Code the HTML script in the HTML file so that a button is placed on the HTML page.

    • 5

      Code the first JavaScript function in the HTML file to generate and send JavaScript information variables to the Flash file for use in the AS3 code. Use the "document.getElementbyID ()" JavaScript method to call the AS3 function in the AS3 file. Specify the first parameter in the "document.getElementbyID ()" method as the registered function id. The registered function id is from the SWF Object id generated when you first created the AS3 SWF file. Specify the second parameter in the "document.getElementbyID ()" method as the registered JavaScript function name of the AS3 function. This is specified in the second parameter of the "ExternalInterface.addCallback()" method in the AS3 file.

    • 6

      Code the second JavaScript function in the HTML file so that it has the function name specified as declared in the "ExternalInterface.call()" method in the AS3 file. Write the code of the JavaScript function so that its arguments list match the parameters list in the "ExternalInterface.call()." Include in the JavaScript code, the necessary commands to change, add or delete objects placed with the HTML code when it receives the information variables from the AS3 file.

Learnify Hub © www.0685.com All Rights Reserved