Understanding fscommand()


The fscommand() function enables a Flash movie to communicate with the application that's currently holding the movie. The following are examples of applications that hold (host) Flash movies:

  • Stand-alone Flash Player

  • Web browser

  • Executable that displays the Flash movie, such as those created by third-party tools discussed later in this lesson; or executables created using C++, Visual Basic, and so on

Note

The ExternalInterface class that was introduced with Flash 8 is generally more powerful than using fscommand() because with ExternalInterface your application can call specific functions (and receive responses) in the application that is holding the SWF file, such as a web browser. However, the fscommand() function is still useful if exporting to Flash 7 or older, or exporting for use in a projector.


It's simple to use fscommand() from within Flash. The fscommand() function accepts two parameters: a command name, and optional extra information. The extra information is used as a parameter of the command:

   fscommand("command_name", "optional extra stuff");


When Flash executes an fscommand(), the host application receives notification that a command has been sent to it. The name of the command is sent, as well as any optional parameter data. The host application must be programmed to deal with these incoming commands; it looks at the name of the incoming command and reacts accordingly, using any optional parameter data to complete the task.

Let's explore in detail some of the previously mentioned uses of the fscommand() function.

Controlling the Stand-Alone Flash Player (Projectors)

Using the Publish settings in Flash, you can publish a Flash movie as a projector. A projector file typically contains your movie as well as the Flash Player. Opening the file causes your movie to play in its own application window (the Flash Player/Projector window). The fscommand() function can be used in your movie so that it can communicate with the projector in various ways. There are six built-in fscommand() functions that the stand-alone player can execute:

   fscommand("quit")


This command closes the stand-alone player window.

   fscommand("fullscreen", true)


or

   fscommand("fullscreen", false)


This command forces the stand-alone player to play at full screen (if true) or at the defined movie size (if false).

   fscommand("allowscale", true)


or

   fscommand("allowscale", false)


This command determines what happens if the user resizes the projector window while your movie is playing. If true, the movie is scaled to fit 100% in the resized stand-alone player window. If false, the player window is still resizable, but the movie playing inside it remains at its original size.

   fscommand("showmenu", true)


or

   fscommand("showmenu", false)


Right-clicking (Ctrl-clicking on a Macintosh) a movie playing in the stand-alone player opens a context menu. The minimal version of this menu is shown if this fscommand() parameter is set to false. The full menu is shown if true.

   fscommand("exec", fileName)


This command executes (opens) another application (such as an .EXE file on Windows). The parameter is the filename of the application to open. Applications opened using this command must reside in a folder named fscommand. This folder must reside in the same directory as the projector.

   fscommand("trapallkeys", true)


or

   fscommand("trapallkeys", false)


If TRue, all key events are sent to the Flash Player. If false, certain key events such as accelerator keypresses are not sent.

Any of these commands can be executed from within your movie using syntax similar to the following:

   myButton_btn.onRelease = function(){      fscommand("quit");    }


Stand-alone fscommand() functions have no effect on Flash movies played outside the stand-alone player.

Executing AppleScripts with fscommand() Functions

AppleScript is a built-in scripting language for the Macintosh operating system. AppleScripts (files containing AppleScript code) are used to tell the operating system to perform tasks such as these:

  • Batch processing

  • File conversion and manipulation

  • Performing tasks at specified times

One of the more powerful aspects of using the exec fscommand() in a Macintosh-based projector is its capability to execute an AppleScript. Let's look at a simple example.

Note

This is not intended to be extensive instruction on how to create AppleScripts, but rather a simple demonstration of how AppleScripts can be executed via Flash. For more information on AppleScript, visit www.apple.com/applescript/.


The following AppleScript opens the file named catalog.pdf on the My CD disk:

   tell application "Finder"    activate    select file "catalog.pdf" of disk "My CD"    open selection    end tell


To execute this AppleScript from Flash, you name it (for example, launchCatalog), save it in the fscommand folder and create a script within your Flash movie similar to the following:

   myButton_btn.onRelease = function(){      fscommand("exec", "launchCatalog");    }


When myButton_btn is clicked, the launchCatalog AppleScript is executed, and catalog.pdf opens.

Communicating with a Web Browser

When a Flash movie is embedded in an HTML page and the page is viewed in a web browser, the fscommand() function enables the Flash movie to communicate with the browser via JavaScript. This feature allows you to do tasks such as open alert boxes, resize the browser, and other JavaScript activities.

Note

Because the success of this communication depends on the specific browser and version, some Flash developers limit their use of the fscommand() function. For more information about using the fscommand to communicate with a browser, visit www.macromedia.com.


Tip

If exporting for use in the Flash 8 player or later, ExternalInterface is the better choice for communication with JavaScript in the web browser. See Lesson 15 for more information on ExternalInterface.


Creating an Enhanced Executable (Projector)

Several companies make software to extend the functionality of a Flash movie. Most of these products take a SWF file and wrap it within a powerful executable shell. This shell can be considered a high-tech "box" that contains your SWF file. The box has been programmed with the capability to perform all sorts of tasks that a typical SWF file can't do. The SWF file controls this powerful box by sending specialized commands to it. Depending on the box, Flash uses fscommand() functions or a custom API provided by this box. Think of the SWF file as the interface and brains of the resulting application, and the box (executable) as the facilitator. These are two of the most popular products that extend Flash:

  • ZincMultidmedia (MDM) Limited (www.multidmedia.com)

  • SWF StudioNorthcode (www.northcode.com)

The following figure illustrates how a SWF file interacts with a Flash wrapper such as Zinc. The white box is the SWF file and the gray box that houses it is the wrapper. The SWF communicates with the wrapper, in this case telling it to save a new text file called myText.txt with the word "Hello" in it. The wrapper accepts the command from the SWF and saves the file to the hard drive.

Note

At this time, only Zinc provides a way to create Applications for both Windows and Mac OS-X.


These applications extend Flash's capabilities with hundreds of commands. Typically, you open the application (such as Zinc), locate the SWF file that makes use of special commands, adjust a few settings, and click the Build button, which creates an .EXE file.

When opened, this file contains and plays your SWF movie, and is sent commands by your movie. The end result is a powerful Flash movie.

The following are a few of the tasks that can be accomplished through the use of one of the identified third-party tools:

  • Create or remove text files or directories

  • Upload and download files from the Internet

  • FTP files from the Internet

  • Force the computer to display the Flash content in DirectX mode

  • Open a file browse pop-up window to allow a user to locate a file or location

  • Save a screenshot of the Flash content or a specific area within the Flash content

  • Set the desktop wallpaper on the user's computer

Although most of the extended functionality that you gain from these software products comes from executing commands in ActionScript, several configurable options can be set directly from the software's interface (to be applied to the executable file that's created):

  • Disable right-click

  • Remove window borders

  • Make the window always run on top of all other windows

  • Assign a custom icon to the executable

  • Include additional files in the executable




Macromedia Flash 8 ActionScript Training from the Source
Macromedia Flash 8 ActionScript: Training from the Source
ISBN: 0321336194
EAN: 2147483647
Year: 2007
Pages: 221

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net