-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParseTest.as
executable file
·132 lines (106 loc) · 3.42 KB
/
ParseTest.as
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package
{
import com.adobe.khoyt.parse.Parse;
import com.adobe.khoyt.parse.events.ParseEvent;
import flash.display.Sprite;
import flash.text.TextField;
public class ParseTest extends Sprite
{
public static const DATA_SIZE:Number = 20;
public static const GAME_SCORE:String = "GameScore";
public static const MAX_SCORE:Number = 5000;
private var count:Number = 0;
private var parse:Parse = null;
private var id:String = null;
private var tf:TextField;
public function ParseTest()
{
super();
init();
}
private function init():void
{
parse = new Parse( Constants.APPLICATION_ID, Constants.REST_API_KEY );
parse.addEventListener( ParseEvent.COUNT, doParseCount );
parse.addEventListener( ParseEvent.CREATE, doParseCreate );
parse.addEventListener( ParseEvent.READ, doParseRead );
parse.addEventListener( ParseEvent.UPDATE, doParseUpdate );
parse.addEventListener( ParseEvent.REMOVE, doParseRemove );
parse.addEventListener( ParseEvent.SEARCH, doParseSearch );
parse.count( GAME_SCORE );
tf = new TextField();
addChild(tf);
tf.border = true;
tf.width = 320 - 50*2;
tf.height = 460 - 50*2;
tf.x = 50;
tf.y = 50;
}
protected function doParseCount( event:ParseEvent ):void
{
var data:Object = null;
count = new Number( event.value );
trace( "Found " + count + " records." );
tf.appendText( "Found " + count + " records. \n");
data = {
score: Math.round( Math.random() * MAX_SCORE ),
playerName: "Sean Plott",
cheatMode: Math.random() > 0.50 ? false : true
};
parse.create( GAME_SCORE, data );
}
protected function doParseCreate( event:ParseEvent ):void
{
var data:Object = null;
trace( "Created: " + event.value.objectId );
tf.appendText("Created: " + event.value.objectId + "\n");
if( count < ( DATA_SIZE - 1 ) )
{
count = count + 1;
data = {
score: Math.round( Math.random() * MAX_SCORE ),
playerName: "Sean Plott",
cheatMode: Math.random() > 0.50 ? true : false
};
parse.create( GAME_SCORE, data );
} else {
id = event.value.objectId;
parse.read( GAME_SCORE, event.value.objectId );
}
}
protected function doParseRead( event:ParseEvent ):void
{
var change:Object = null;
trace( "Read full record: " + event.value.playerName );
tf.appendText( "Read full record: " + event.value.playerName + "\n");
change = {
playerName: "Kevin Hoyt"
};
parse.update( GAME_SCORE, event.value.objectId, change );
}
protected function doParseRemove( event:ParseEvent ):void
{
trace( "Object " + id + " removed." );
tf.appendText( "Object " + id + " removed." + "\n");
parse.search( GAME_SCORE, {playerName: "Kevin Hoyt"} );
}
protected function doParseSearch( event:ParseEvent ):void
{
if( id != null )
{
trace( "Found " + event.value.length + " matching records." );
tf.appendText("Found " + event.value.length + " matching records." + "\n");
id = null;
parse.search( GAME_SCORE, {playerName: "Sean Plott"}, 200, 100 );
} else {
trace( "Got " + event.value.length + " matching records." );
}
}
protected function doParseUpdate( event:ParseEvent ):void
{
trace( "Updated at: " + event.value.updatedAt );
tf.appendText( "Updated at: " + event.value.updatedAt + "\n");
parse.remove( GAME_SCORE, id );
}
}
}