View comments | RSS feed

fscommand function

fscommand(command:String, parameters:String) : Void

Lets the SWF file communicate with either Flash Player or the program that is hosting Flash Player, such as a web browser. You can also use the fscommand() function to pass messages to Macromedia Director, or to Visual Basic (VB), Visual C++, and other programs that can host ActiveX controls.

The fscommand() function lets a SWF file communicate with a script in a web page. However, script access is controlled by the web page's allowScriptAccess setting. (You set this attribute in the HTML code that embeds the SWF file--for example, in the PARAM tag for Internet Explorer or the EMBED tag for Netscape. When allowScriptAccess is set to "never", a SWF file cannot access web page scripts. With Flash Player 7 and later, when allowScriptAccess is set to "always", a SWF file can always access web page scripts. When allowScriptAccess is set to "sameDomain", scripting is allowed only from SWF files that are in the same domain as the web page; scripting is always allowed with previous versions of Flash Player. If allowScriptAccess is not specified in an HTML page, the attribute is set by default to "sameDomain" for SWF files of version 8 and later, and to "always" for SWF files of version 7 and earlier.

Usage 1: To use fscommand() to send a message to Flash Player, you must use predefined commands and parameters. The following table shows the values that you can specify for the fscommand() function's command and parameters parameters. These values control SWF files that are playing in Flash Player, including projectors. (A projector is a SWF file saved in a format that can run as a stand-alone application--that is, without Flash Player.)

Command

Parameter

Purpose

quit

None

Closes the projector.

fullscreen

true or false

Specifying true sets Flash Player to full-screen mode. Specifying false returns the player to normal menu view.

allowscale

true or false

Specifying false sets the player so that the SWF file is always drawn at its original size and never scaled. Specifying true forces the SWF file to scale to 100% of the player.

showmenu

true or false

Specifying true enables the full set of context menu items. Specifying false hides all of the context menu items except About Flash Player and Settings.

exec

Path to application

Executes an application from within the projector.

trapallkeys

true or false

Specifying true sends all key events, including accelerator keys, to the onClipEvent(keyDown/keyUp) handler in Flash Player.

Availability:

The exec command can contain only the characters A-Z, a-z, 0-9, period (.), and underscore (_). The exec command runs in the subdirectory fscommand only. In other words, if you use the exec command to call an application, the application must reside in a subdirectory named fscommand. The exec command works only from within a Flash projector file.

Usage 2: To use fscommand() to send a message to a scripting language such as JavaScript in a web browser, you can pass any two parameters in the command and parameters parameters. These parameters can be strings or expressions, and they are used in a JavaScript function that handles, or catches, the fscommand() function.

In a web browser, fscommand() calls the JavaScript function moviename_DoFScommand, which resides in the webpage that contains the SWF file. For moviename, supply the name of the Flash object that you used for the NAMEattribute of the EMBED tag or the ID property of the OBJECT tag. If you assign the SWF file the name myMovie, the JavaScript function myMovie_DoFScommand is called.

In the web page that contains the SWF file, set the allowScriptAccess attribute to allow or deny the SWF file's ability to access the web page. (You set this attribute in the HTML code that embeds the SWF file--for example, in the PARAM tag for Internet Explorer or the EMBED tag for Netscape.) When allowScriptAccess is set to "never", outbound scripting always fails. When allowScriptAccess is set to "always", outbound scripting always succeeds. When it is set to "sameDomain", scripting is allowed only from SWF files that are in the same domain as the web page. If allowScriptAccess is not specified in a web page, it defaults to "sameDomain" for Flash Player 8, and to "always" for previous versions of Flash Player.

When using this function, consider the Flash Player security model. For Flash Player 8, the fscommand() function is not allowed if the calling SWF file is in the local-with-file-system or local-with-network sandbox and the containing HTML page is in an untrusted sandbox. For more information, see the following:

Usage 3: The fscommand() function can send messages to Macromedia Director. These messages are interpreted by Lingo (the Director scripting language) as strings, events, or executable Lingo code. If a message is a string or an event, you must write the Lingo code to receive the message from the fscommand() function and carry out an action in Director. For more information, see the Director Support Center at www.macromedia.com/support/director.

Usage 4: In VisualBasic, Visual C++, and other programs that can host ActiveX controls, fscommand() sends a VB event with two strings that can be handled in the environment's programming language. For more information, use the keywords "Flash method" to search the Flash Support Center at www.macromedia.com/support/flash.

Note: If you are publishing for Flash Player 8 or later, the ExternalInterface class provides better functionality for communication between JavaScript and ActionScript (Usage 2) and between ActionScript and VisualBasic, Visual C++, or other programs that can host ActiveX controls (Usage 4). You should continue to use fscommand() for sending messages to Flash Player (Usage 1) and Macromedia Director (Usage 3).

Availability: ActionScript 1.0; Flash Player 3

Parameters

command:String - A string passed to the host application for any use, or a command passed to Flash Player.

parameters:String - A string passed to the host application for any use, or a value passed to Flash Player.

Example

In the following example, fscommand() sets Flash Player to scale the SWF file to the full monitor screen size when the fullscreen_btn or unfullscreen_btn button is released:

this.fullscreen_btn.onRelease = function() {
 fscommand("fullscreen", true);
};

this.unfullscreen_btn.onRelease = function() {
 fscommand("fullscreen", false);
};

The following example applies fscommand() to a button in Flash for the purpose of opening a JavaScript message box in an HTML page. The message itself is sent to JavaScript as the fscommand parameter.

You must add a function to the web page that contains the SWF file. This function, myDocument_DoFSCommand(), waits for an fscommand() call. When fscommand() is triggered in Flash (for example, when a user clicks the button), the command and parameter strings are passed to the myDocument_DoFSCommand()function. You can use the passed strings in your JavaScript or VBScript code in any way you like. In this example, the function contains a conditional if statement that checks to see if the command string is "messagebox". If it is, a JavaScript alert box displays the contents of the fscommand() function's parameters string.

function myDocument_DoFSCommand(command, args) {
 if (command == "messagebox") {
 alert(args);
 }
}

In the Flash document, add fscommand() to a button:

fscommand("messagebox", "This is a message box called from within Flash.")

You can use expressions for the parameters of the fscommand() function, as shown in the following example:

fscommand("messagebox", "Hello, " + name + ", welcome to our website!")

To test the SWF file, select File > Publish Preview > HTML. If you publish your SWF file using the Flash with FSCommand template (in the Publish Settings dialog box, select the HTML tag), Flash inserts the myDocument_DoFSCommand() function automatically. The SWF file's NAME and ID attributes will be the filename. For example, for the file myDocument.fla, the attributes would be set to myDocument.

See also

ExternalInterface (flash.external.ExternalInterface)


Version 8

Comments


No screen name said on Sep 19, 2005 at 3:24 PM :
Hmmm. I've named my flash movie main_flash and tried using fscommand to call javascript function main_flash_DoFSCommand(c,p) and it didnt work.
No screen name said on Sep 20, 2005 at 2:05 AM :
I have Flash content authored in Flash 7. I have downloaded and installed Flash prof 8 (which includes Flash Player 8).

My content uses fscommand extensively. I have updated my html (running on Internet Explorer 6) with <PARAM NAME="allowScriptAccess" VALUE="always">

Fscommands work as expected when downloaded from a webserver (http) but do not work at all (they are ignored) when run from the localsystem (c:\app\index.html).

I am not using any cross domain resources (all swf, xml and html files ar in the same folder or a child folder.)

I have tested this issue with Flash 8 authoring aswell. (fcommands are ignored)
No screen name said on Oct 3, 2005 at 7:25 AM :
Yep - I too use fscommand quite a lot - and now I'm screwed.
Most of my stuff is run on the local file system, and ever since the upgrade to flash 8, none of the fscommands work.
Is there even a work around for this?
shimi2 said on Oct 3, 2005 at 1:02 PM :
Flash Player 8 introduces security restrictions on local SWFs. This DevNet article describes the changes and what you might need to do to ensure your content doesn't break:
http://www.macromedia.com/devnet/flash/articles/fplayer8_security.html

This help page specifically describes how to configure Flash Player 8 for testing purposes:
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html
(For the Flash author whose content is deployed locally, your users will need to use the Settings Mgr to configure their Flash Player, if the local content was published in Flash Player 7 and uses fscommand to communicate w/the Internet.
No screen name said on Oct 3, 2005 at 11:36 PM :
I found this page usefull

http://livedocs.macromedia.com/flash/8/main/00001613.html
No screen name said on Oct 17, 2005 at 1:20 PM :
I am using the TShockwavePlugin control inside Delphi OCX's to embed SWF controls that act as buttons and other GUI driven controls. The FSCOMMAND, TCallLabel, GetVariable, SetVariable functions seem to function OK on the development machine I am using but not when the OCX is deployed. As the SWF is embeded and not loaded from a server what publishing options should I be using to enable this to function as with the Flash 7 plugin ?
jarriaza said on Nov 24, 2005 at 8:45 AM :
I'm using the fscommand this way:
on(release) {
trace("debug");
fscommand("exec", "myapp.exe");
}

but when the button is pressed it does nothing, I'm running Flash8, FlashMX 2004 both Pro, the trace command executes ok, but the fscommand doesn't.
Is this a Flash ver. XX problem ?? I've seen apps from previous versions running this command fine.
Help will be appreciated.
rawfish said on Dec 1, 2005 at 1:07 PM :
The issue is using:
fscommand("fullscreen", true);

we have used this extensively in the past and now that we've upgraded to flash8 we are having difficulty with it. On some macs the menu bar is showing and on other macs the projector will go full screen. We did a little workaround like this:

frame1: fscommand("fullscreen", true);
frame2: fscommand("fullscreen", false);
frame3: fscommand("fullscreen", true);
fscommand("showmenu", false);
fscommand("allowcale", true);
loadMovieNum("menu.swf",1);
stop();

this works although it's not ideal as there's a flash at the beginning but if escape is pressed the projector will shrink as it's supposed to, but then the next time someone opens the projector the menu bars will return.

Has anyone else had this problem and does anyone know of a fix?
Sleevz said on Jan 17, 2006 at 11:54 PM :
I tried using FScommand for communicating with VB. I can pass information from Flash to VB but it's not possible the other way around. I want VB to be able to pass a parameter so that flash can take in the corresponding value and act accordingly.

Does anyone have any ideas?
Sleevz said on Jan 23, 2006 at 4:27 AM :
Oh well, found the solution to my own problem. VB6 can directly send values to a variable used in flash by using the set variable parameter. (<flashname>.setvariable) and then the variable name passes the value from VB6 to Flash 8 successfully.
Ritul Ranjan said on Sep 21, 2006 at 2:55 AM :
I am trying to incorporate a flash movie in an ActiveX control, by embedding Flash ActiveX control in my control. The communication between flash and my control is done using FSCommand().

This works fine in ActiveX Test Container. However, when I embed my control on a web page and open the web page using Internet Explorer, the communication does not seem to work!

Why is this so? Am I doing something wrong?
No screen name said on Sep 29, 2006 at 4:16 AM :
Hi everybdy !

FSCOMMAND was truly Fantastic command for the presentation in earlier version it used work without a fuss.

NOW the sub folder thing isn't happening ... i have few WMV's that i want to open externally (as there low FLV version is already embed in presentation)

All the WMVs are under fscommand folder as its been suggested in document... and command on the button goes like this.
---------
on (release) {
fscommand("exec", "showreel.wmv");
}
--------

now what mistake i m making here... OR .... this finction doesn't work.

Please suggest me solution for this ...

Thanks and Regards

Pankaj Kashyap
panksplay@yahoo.com
Bitey said on Nov 28, 2006 at 8:01 PM :
I was more interested in fscommand changes in the projectors. This article cleared it all up: http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_14280

Looks like all executable files launched by fscommand have to be placed in a folder labeled "fscommand" at the same level as the projector. Use batch files if you need to get out of the sandbox and into another portion of your CD-ROM or HDD.
rune warhuus said on Feb 5, 2007 at 12:44 PM :
When making a projector file from the 9.0.28 standalone player for Intel OS X the fscommand function does not work. I have am trying to call "myapp.app" witch resides in a "fscommand" subfolder. This is the code:
"fscommand("exec", "myapp.app");"
It works fine when using the version 8 rosetta player, but it does not work with the Universal Binary 9.0.28. Can anyone help me?
juankpro said on Aug 1, 2007 at 8:07 AM :
FSCommand does not works because from Flash Player 8 there are security issues which helps maintain user private information out of the reach of hackers. Even though an SWF and HTML files are in the same local drive, no one can assure that the HTML file is not going to try to read and send local data to the network or viceversa, that is why every user must tell the SWF to be trusted so it can communicate to the HTML page.

To avoid this problems users can create installer which will install special files that allows the application to communicate to the HTML page, read: http://www.macromedia.com/devnet/flash/articles/fplayer8_security.html

When using the exec, you can only run .com, .exe and .bat files placed in a folder called fscommand placed in the same folder as the projector. So to open different files or to execute files in pther folder, create a bat file. You cannot send parameters to the executable file.

When communicating to an Activex control use the controlName_FSCommand event to send messages from Flash to the hosting application. You can change Flash variables from the hosting application and create a watch inside Flash so en event is run when the variable is changed instead of listening to it on every frame.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001727.html