Communicating Locally


Your published .swf file exists in various contexts. For example, a .swf can be embedded in an HTML document and viewed in a browser window or as a standalone document in a Flash Projector. This section discusses how your .swf file can communicate with these environments.

Note

Flash can be published in various formats, including as a .swf file displayed by an HTML document, a standalone executable file for Windows or Macintosh (called a Projector), or even as a QuickTime movie.


Controlling Browser Windows

One of the common uses of Flash is to provide dynamic and interactive navigational elements for an HTML website. You might do this when you want the navigation to have more interaction (like animated roll-over effects) than a list of HTML links. Although you can create similar effects with JavaScript, Flash has the advantage of cross-platform performance. A Flash navigation element runs essentially the same in any browser that has a Flash Player installed.

To create "links" analogous to the <A HREF > tag in HTML, use the getURL() function. For example, a symbol named "home" in the navigation menu could have the following code attached to it programmatically:

home_btn.onRelease() = function{     getURL("home.html"); }


Now, when the user clicks on that button, Flash passes the URL parameter in parentheses to the browser, which then loads a new page into the browser window.

You can also use the getURL command to pass URL-encoded data or a database query, as shown in the following example:

image_10.onRelease() = function{     getURL("images.html?id=10"); }


Just as with HTML <A HREF> tags, you can specify the target by adding a second parameter to be passed to the getURL() command. For example, to open a new window with the target attribute, you can use code similar to this:

image_10.onRelease() = function{     getURL("images.html?id=10", "_blank"); }


Now you know how to communicate with the browser using the getURL command in Flash. The next section briefly discusses another way to communicate with the browser: using JavaScript.

JavaScript

JavaScript is a scripting language that is used to communicate with a browser. ActionScript is based on the same code standard and is a close relative of JavaScript. You can use JavaScript in your Flash projects to help you communicate with the browser, although JavaScript itself has some cross-browser and platform issues that you have to stay aware of because they can limit what can be accomplished with a simple script. For example, JavaScript code that works in one browser may not function at all in another.

Controlling a Flash Projector

You can use the fscommand() command to control certain aspects of the performance of the standalone Flash projector. When a .swf is presented in a standalone projector, instead of as an embedded file in an HTML document, it exists in the context of the projector that plays the .swf.

To enlarge the projector display window to fill the user's entire screen, use the fullscreen attribute of the fscommand statement. When fullscreen is set to true, the projector fills the screen, as shown in the following example:

fscommand("fullscreen", true);


When at full screen, the movie fills the entire window and no borders are visible. Although this can be a nice visual effect, be sure to give the end user control over how the movie is displayed.

When fullscreen is set to false, the projector opens at the size you set in the Document settings, as shown in the following example:

fscommand("fullscreen", false);


Tip

It is generally considered best practice to begin with a non full screen SWF and then provide a button to expand to full screen and one to reduce the display to original size.


Another useful command controls the scaling of the movie. The allowscale parameter of the fscommand enables you to control whether the SWF file stays the same size even when the browser window is expanded and contracted by the user. When the parameter is set to true, it allows the SWF movie to expand and contract with the browser window. To turn off scaling use the following command:

fscommand("allowscale", false);


Be aware that if you have a lot of bitmap artwork that has been optimized for file size in your movie, it might be a good idea to set the allowscale parameter to false. Otherwise, the images might appear pixilated when enlarged.



Special Edition Using Macromedia Studio 8
Special Edition Using Macromedia Studio 8
ISBN: 0789733854
EAN: 2147483647
Year: 2003
Pages: 337

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