This tutorial is a basic tutorial for Flash devlopers who want to create a user-interactive movie and allow users to store the data using php or the shared object. In the following I will mainly focus on the php version, which is a AS2 class file. The downloadable files, however, also contain a file where the shared object is applied.

Now let's start. First test the movie to see its functionality.

The Flash AS file

In the following we will look at the script. I prefer AS2 class scripts, because they have to be "clean" with all the correct datatypes. The movie is set up as one movieclip with a linkage id. As AS2 class we enter Memory, which is the name of the class file. We place one instance of this movieclip on stage and give it a name like mcGame. Then we 2 functions on the main timeline for saving and the stored data and setting the stage from the stored data. Also we place the commands to move the squares aroud here.
// FLA FILE SCRIPT
//
// Functions to set the stage and store data
//
mcGame.setStage ();
mcGame.storeData ();
//
// drag functions for the movieclips.
//
mcGame.square1.onPress = function () {
	this.startDrag ();
};
mcGame.square1.onRelease = function () {
	this.stopDrag ();
};
mcGame.square2.onPress = function () {
	this.startDrag ();
};
mcGame.square2.onRelease = function () {
	this.stopDrag ();
};
mcGame.square3.onPress = function () {
	this.startDrag ();
};
mcGame.square3.onRelease = function () {
	this.stopDrag ();
};
mcGame.square4.onPress = function () {
	this.startDrag ();
};
mcGame.square4.onRelease = function () {
	this.stopDrag ();
};

The XML file

Now it is time to have a closer look at the AS2 file. What do we want to achieve?
  • 1. We want the positions of the squares being stored in our individual file.
  • 2. We want to be able to retrieve those data at a later stage, to show it to others ot to continue working on it if it is a complex file.
So we basically need two functions for that. Then we need to know how to store the data. There are two possibilities either as a textfile with all individual points listed as variables or as an xml file. Textfiles can become too massy especially with a lot of data, so I decided to use an xml file. An example is shown below. We have nodes for each square with attributes for the positions. We could have written it differently as well and use childnodes for the x and y values. That is up to you and may be a good exersize.
<?xml version="1.0"?>
<game>
	<square1 x_value="-143" y_value="53">square1</square1>
	<square2 x_value="137.95" y_value="-97">square2</square2>
	<square3 x_value="-42" y_value="24">square3</square3>
	<square4 x_value="-19.05" y_value="-134">square4</square4>
</game>
On the next page we will discuss the AS2 script Memory.as.

NEXT PAGE

1      2      3      4