forked from markstar/StatefulToolkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSaveLoadExample.as
More file actions
68 lines (54 loc) · 2.02 KB
/
SaveLoadExample.as
File metadata and controls
68 lines (54 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package
{
import com.bit101.components.PushButton;
import couk.markstar.examples.ui.CircleContainer;
import couk.markstar.statefultoolkit.utils.FileUtil;
import couk.markstar.statefultoolkit.utils.IFileUtil;
import flash.display.Sprite;
import flash.events.MouseEvent;
[SWF( backgroundColor='#F3F3F3',frameRate='30',width='592',height='300' )]
public class SaveLoadExample extends Sprite
{
protected var _saveButton:PushButton;
protected var _loadButton:PushButton;
protected var _circleContainer:CircleContainer;
protected var _fileUtil:IFileUtil;
/**
* Create the save and load buttons to save and load the state. Then create the circle container and register it with the FileUtil,
* by registering the container with the FileUtil it means the FileUtil knows which statable object to retrieve and set the state on
* when save and load are executed.
*/
public function SaveLoadExample():void
{
// PushButton( parent, x, y, label, MouseEvent.CLICK event listener )
_saveButton = new PushButton( this, 196, 275, "Save", saveClickListener );
_loadButton = new PushButton( this, 295, 275, "Load", loadClickListener );
_circleContainer = new CircleContainer();
_fileUtil = new FileUtil();
_fileUtil.registerObject( _circleContainer );
addChild( _circleContainer );
initDefaultState();
}
protected function saveClickListener( e:MouseEvent ):void
{
_fileUtil.save();
}
protected function loadClickListener( e:MouseEvent ):void
{
_fileUtil.load();
}
/**
* Initialise the circle container with four circles
*/
protected function initDefaultState():void
{
var defaultState:String = '<container>';
defaultState += '<object><x>196</x><y>100</y></object>';
defaultState += '<object><x>196</x><y>200</y></object>';
defaultState += '<object><x>396</x><y>100</y></object>';
defaultState += '<object><x>396</x><y>200</y></object>';
defaultState += '</container>';
_circleContainer.setState( new XML( defaultState ) );
}
}
}