In this example, we will create a screensaver that allows the user to change its settings.
To save and use these user-defined settings, we will use the advanced FSCommand features.
Do the following to create a screensaver with settings:
You will find the screensaver FLA files out of which “Screensaver2.swf” and “Settings.swf” were created in the 'FLA' directory.
Screensaver2.swf description:
Consists of 100 frames.
The 1st frame contains the following ActionScript:
stop();
var isGreen="N";
function watchCallback (id, oldval, newval) {
if(newval!="Y") {
gotoAndPlay(10);
} else {
gotoAndPlay(60);
}
};
_root.watch("isGreen", watchCallback);
fscommand("storage.get","Green,isGreen");
Comments:
stop();
Wwe stop the playback to initialize the screensaver and decide
which part of the movie to play.
var isGreen="N";
We initialize the variable into which we will
read whether the green color has been selected.
function watchCallback (id, oldval, newval)
This function will be used
right after the record from the settings storage will be read. It analyzes
the value of the records and jumps to the 10th frame if the green color
is not selected, otherwise it jumps to the 60th frame.
_root.watch("isGreen",
watchCallback);
We use this watch function call to enable listening to the isGreen variable.
When the variable gets the value, the watchCallback function will be
called.
fscommand("storage.get","Green,isGreen");
We use this call to read the value of Green from the settings storage
and assign it to the isGreen variable.
Note. We cannot just read the value using FSCommand(“storage.get”,””) and jump to the necessary frame because the FSCommand function is asynchronous and returns execution immediately before the value is actually assigned. That is why we need to introduce the listening function that is executed after the value is assigned.
Frames 10-50:
Bouncing gray ball animation.
The 50th frame also contains the ActionScript for looping the animation:
gotoAndPlay(10);
Frames 60-100:
Bouncing green ball animation.
The 100th frame also contains the ActionScript for looping the animation:
gotoAndPlay(60);
Settings.swf description:
Consists of one frame.
The frame contains two RadioButtons: option1 (gray ball) and option2
(green ball).
Option1 contains the following ActionScript:
on (release) {
fscommand("storage.set","Green,N");
}
Option2 contains the following ActionScript:
on (release) {
fscommand("storage.set","Green,Y");
}
When the user selects the first option, “Green” is saved to the settings storage with the “N” value. When the user selects the second option, “Green” is saved with the “Y” value.
Also, the frame contains the following ActionScript for initializing the options:
stop();
var isGreen="N";
function watchCallback (id, oldval, newval)
{
if(newval!="Y") {
option1.setState(true);
} else {
option2.setState(true);
}
};
_root.watch("isGreen", watchCallback);
fscommand("storage.get","Green,isGreen");
All rights reserved © 2007 ChameleonFlash.com