Sending messages to and from Flash Player
665
4.
Select Frame 1 of the Actions layer, and add the following ActionScript in the
Actions panel:
window_btn.onRelease = function() {
fscommand("popup", "http://www.macromedia.com/");
};
alert_btn.onRelease = function() {
fscommand("alert", "You clicked the button.");
};
5.
Select File > Publish Settings, and make sure that Flash with FSCommand is selected in the
Template menu on the HTML tab.
6.
Select File > Publish to generate the SWF and HTML files.
7.
In an HTML or text editor, open the HTML file that was generated in step 6 and examine
the code. When you published your SWF file using the Flash with FSCommand template
on the HTML tab of the Publish Settings dialog box, some additional code was inserted in
the HTML file. The SWF file’s
NAME
and
ID
attributes are the filename. For example, for
the file myMovie.fla, the attributes would be set to
myMovie
.
8.
In the HTML file, add the following JavaScript code where the document says
// Place
your code here.
:
if (command == "alert") {
alert(args);
} else if (command == "popup") {
window.open(args, "mmwin", "width=500,height=300");
}
(For more information about publishing, see
Chapter 17, “Publishing”
in
Using Flash.
)
Alternatively, for Microsoft Internet Explorer applications, you can attach an event
handler directly in the
<SCRIPT>
tag, as shown in this example:
<script Language="JavaScript" event="FSCommand (command, args)"
for="theMovie">
...
</script>
9.
Save and close the HTML file.
When you’re editing HTML files outside of Flash in this way, remember that you must
deselect the HTML check box in File > Publish Settings, or your HTML code is
overwritten by Flash when you republish.
10.
In a web browser, open the HTML file to view it. Click the Open Window button; a
window is opened to the Macromedia website. Click the Alert button; an alert
window appears.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...