How to Skip a Flash Movie
Today, there are dozens of websites that employ Flash animations in nearly all aspects of their design. Since content is still king, it is important that users get to the meat of the website as quickly as possible. At the same time, there needs to be a balance between the design and the functionality of the website. When using Flash, it is possible to give visitors the option of skipping Flash movie intros and getting straight into the website. With only a few lines of code in ActionScript, one can easily skip a flash movie.
Instructions
-
-
1
Fire up your Flash application and import the necessary artwork. Alternatively, create your own Flash animation from scratch (see Resources for information on how to do so).
-
2
Insert a new layer and name it "Actions."
-
-
3
Click frame 1 of the "Actions" layer and press F9 to open up the "Actions" panel.
-
4
Create a variable called "so" and invoke the "getLocal()" method of the "SharedObject" class as follows:
var so:SharedObject = SharedObject.getLocal ( "eHowBanner");
The "SharedObject" instance means that this variable cannot be set to some other variable object like a number or a string.
-
5
Create an "if" statement to determine what to do if the user has visited before. The code is:
If ( so.data.alreadyvisited == true) {
gotoAndStop (100);
}The "alreadyvisited" property is checked if the visitor has been there before. If it is true, the Flash movie skips to frame 100, otherwise the animation simply unfolds from the beginning.
-
6
Insert the skipping code as follows:
var so:SharedObject = SharedObject.getLocal ("eHowBanner");
if (so.data.alreadyvisited == true) {
gotoAndStop (100);
}This code allows the banner to play through during the first viewing, but skip on subsequent viewings.
-
7
Drag the playhead to frame 100 and insert a new keyframe on the "Actions" layer.
-
8
Select the new keyframe and press F9.
-
9
Add the code:
Stop();
This stops the flash movie from looping.
-
10
Add the line:
So.data.alreadyvisited = true;
So.flush ();The line "so.flush ();" is not mandatory. It allows Flash to update the current state of the shared object, which can still be done automatically when the flash movie closes.
-
11
Insert the final code as shown below:
Stop();
So.data.alreadyvisited = true;
So.flush(); -
12
Save and publish the Flash movie by choosing "File", then "Publish."
-
1
Tips & Warnings
The "getLocal ()" method is used to retrieve a cookie from the hard drive. If this cookie does not exist, it is created.
References
Resources
- Photo Credit Flag of movie image by Yuriy Panyukov from Fotolia.com