Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 23. Scripting Java Applets and F... > Scripting Flash 8 - Pg. 589

Example 23-5. Scripting a Flash movie (continued) } // This is the function that is called when Flash calls fscommand( ). // The two arguments are strings supplied by Flash. // This function must have this exact name, or it will not be invoked. // The function name begins with "movie" because that is the id/name of // the <object> and <embed> tags used earlier. function movie_DoFSCommand(command, args) { if (command=="loaded") { // When Flash tells us it is loaded, we can enable the form button. document.f.button.disabled = false; } else if (command == "mousedown") { // Flash tells us when the user clicks the mouse. // Flash can only send us strings. We've got to parse them // as necessary to get the data that Flash is sending us. var coords = args.split(","); alert("Mousedown: (" + coords[0] + ", " + coords[1] + ")"); } // These are some other useful commands. else if (command == "debug") alert("Flash debug: " + args); else if (command == "eval") eval(args); } </script> <script language="VBScript"> ' This script is not written in JavaScript, but Microsoft's ' Visual Basic Scripting Edition. This script is required for Internet ' Explorer to receive fscommand( ) notifications from Flash. It will be ' ignored by all other browsers since they do not support VBScript. ' The name of this VBScript subroutine must be exactly as shown. sub movie_FSCommand(byval command, byval args) call movie_DoFSCommand(command, args) ' Just call the JavaScript version end sub </script> Client-Side JavaScript 23.5 Scripting Flash 8 Version 8 of the Flash Player includes a class named ExternalInterface that revolu- tionizes Flash scripting by greatly simplifying JavaScript-to-Flash communication and Flash-to-JavaScript communication. ExternalInterface defines a static call( ) function for calling named JavaScript functions and obtaining their return values. It also defines a static addCallback( ) method for exporting ActionScript functions for use by JavaScript. ExternalInterface is documented in Part IV. To demonstrate the ease of scripting with ExternalInterface, let's convert Examples 23-4 and 23-5 to use it. Example 23-6 lists the converted ActionScript code, and Example 23-7 shows the converted JavaScript code (the <object> , <embed> , and <form> tags are not altered from Example 23-5 and are omitted here). Scripting Flash 8 | This is the Title of the Book, eMatter Edition Copyright © 2008 O'Reilly & Associates, Inc. All rights reserved. 589