Example: Screensaver with settings
We will create a screensaver that allows the user to change its settings
in this example.
To save and use these user-defined settings, we will
use the advanced FSCommand features.
Do the following to create a screensaver with settings:
- Open SWF Maestro SCR.
- Click “New > New From...” and select the project file
created in the previous example. It will allow us to use the existing
project as a template.
- Open “Files > Files for compilation ”.
- Specify the path to the file “Screensaver2.swf” in
the “Tutorials\Screensaver2” directory.
This file uses the ‘FSCommand(“storage.get”,””)’ call
to find out whether the ball should be green or gray.
- Enable the “Screensaver > Settings menu” option and
specify the path to the file “Settings.swf” that will allow
the user to select the color of the ball. This file uses the ‘FSCommand(“storage.set”,””)’ call
to save the selected color.
- Click “Save As” to save the project.
- Compile the screensaver.
- Copy the final SCR file to the System32 subdirectory of the directory
where Windows is installed.
- Go to the “Display” settings and select your screensaver
from the list.
- Click “Settings” in order to select the color and then
click “Preview”.
You will find the screensaver FLA files out of which “Screensaver2.swf” and “Settings.swf” were
created in the 'Tutorials\FLAs' 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"); |