User Guide

Controlling SWF file playback 181
// Plays the Timeline that contains the button
play();
}
This same on() event handler code produces a different result when attached to a movie clip
object rather than a button. When attached to a button object, statements made within an
on()
handler are applied to the Timeline that contains the button, by default. However, when attached
to a movie clip object, statements made within an
on() handler are applied to the movie clip to
which the
on() handler is attached.
For example, the following
onPress() handler code stops the Timeline of the movie clip to
which the handler is attached, not the Timeline that contains the movie clip:
//Attached to the myMovie_mc movie clip instance
myMovie_mc.onPress() {
stop();
}
The same conditions apply to onClipEvent() handlers attached to movie clip objects. For
example, the following code stops the Timeline of the movie clip that bears the
onClipEvent()
handler when the clip first loads or appears on the Stage:
onClipEvent(load) {
stop();
}
Jumping to a different URL
To open a web page in a browser window, or to pass data to another application at a defined URL,
you can use the
getURL() global function or the MovieClip.getURL() method. For example,
you can have a button that links to a new website, or you can send Timeline variables to a CGI
script for processing in the same way as you would an HTML form. You can also specify a target
window, the same as you would when targeting a window with an HTML anchor
(
<a></a>) tag.
For example, the following code opens the macromedia.com home page in a blank browser
window when the user clicks the button instance named
homepage_btn:
//Attach to frame
homepage_btn.onRelease = function () {
getURL("http://www.macromedia.com", "_blank");
};
You can also send variables along with the URL, using GET or POST methods. This is useful if the
page you are loading from an application server, such as a ColdFusion Server (CFM) page, expects
to receive form variables. For example, suppose you want to load a CFM page named
addUser.cfm that expects two form variables,
name and age. To do this, you can create a movie
clip named
variables_mc that defines those two variables, as shown in the following example:
variables_mc.name = "Francois";
variables_mc.age = 32;