-
Notifications
You must be signed in to change notification settings - Fork 123
/
Main.as
248 lines (177 loc) · 8.53 KB
/
Main.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**
* Copyright 2017 FreshPlanet
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package {
import com.freshplanet.ane.AirFacebook.FBAccessToken;
import com.freshplanet.ane.AirFacebook.FBDefaultAudience;
import com.freshplanet.ane.AirFacebook.FBLoginBehaviorAndroid;
import com.freshplanet.ane.AirFacebook.FBLoginBehaviorIOS;
import com.freshplanet.ane.AirFacebook.FBProfile;
import com.freshplanet.ane.AirFacebook.FBShareDialogModeAndroid;
import com.freshplanet.ane.AirFacebook.FBShareDialogModeIOS;
import com.freshplanet.ane.AirFacebook.Facebook;
import com.freshplanet.ane.AirFacebook.appevents.FBEvent;
import com.freshplanet.ane.AirFacebook.share.FBAppInviteContent;
import com.freshplanet.ane.AirFacebook.share.FBGameRequestActionType;
import com.freshplanet.ane.AirFacebook.share.FBGameRequestContent;
import com.freshplanet.ane.AirFacebook.share.FBGameRequestFilter;
import com.freshplanet.ane.AirFacebook.share.FBShareLinkContent;
import com.freshplanet.ui.ScrollableContainer;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.events.Event;
import flash.net.URLRequestMethod;
/**
* Make sure you replace instances of {YOUR_FACEBOOK_ID} in this file and Main.xml
*/
[SWF(backgroundColor="#057fbc", frameRate='60')]
public class Main extends Sprite {
public static var stageWidth:Number = 0;
public static var indent:Number = 0;
private var _scrollableContainer:ScrollableContainer = null;
public function Main() {
this.addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
}
private function _onAddedToStage(event:Event):void {
this.removeEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
this.stage.align = StageAlign.TOP_LEFT;
stageWidth = this.stage.stageWidth;
indent = stage.stageWidth * 0.025;
_scrollableContainer = new ScrollableContainer(false, true);
this.addChild(_scrollableContainer);
if (!Facebook.isSupported) {
trace("Facebook ANE is NOT supported on this platform!");
return;
}
/**
* set these up before any use to make sure you catch everything
*/
Facebook.logEnabled = true;
Facebook.nativeLogEnabled = true;
/**
* init the ANE!
*/
var ane:Facebook = Facebook.instance;
ane.init("{YOUR_FACEBOOK_ID}", _initCallback);
var blocks:Array = [];
/**
* methods for performing specific actions (visible to users)
* mess with the values to mimic your own app!
*/
blocks.push(new TestBlock("logInWithReadPermissions", function():void {
ane.logInWithReadPermissions(["email", "user_birthday", "user_friends"],
_logInWithReadPermissionsCallback);
}));
blocks.push(new TestBlock("logInWithPublishPermissions", function():void {
ane.logInWithReadPermissions(["publish_actions"],
_logInWithPublishPermissionsCallback);
}));
blocks.push(new TestBlock("accessToken", function():void {
var token:FBAccessToken = ane.accessToken;
trace(token);
}));
blocks.push(new TestBlock("profile", function():void {
var profile:FBProfile = ane.profile;
trace(profile);
}));
blocks.push(new TestBlock("canPresentShareDialog", function():void {
var canPresentShareDialog:Boolean = ane.canPresentShareDialog;
trace("canPresentShareDialog:" + canPresentShareDialog);
}));
blocks.push(new TestBlock("requestWithGraphPath", function():void {
var graphPath:String = "";
var parameters:Object = {};
ane.requestWithGraphPath(graphPath,
parameters,
URLRequestMethod.GET,
_requestWithGraphPathCallback);
}));
blocks.push(new TestBlock("shareLinkDialog", function():void {
var shareLinkContent:FBShareLinkContent = new FBShareLinkContent();
shareLinkContent.contentDescription = "";
shareLinkContent.contentTitle = "";
shareLinkContent.imageUrl = "";
ane.shareLinkDialog(shareLinkContent,
false,
_shareLinkDialogCallback);
}));
blocks.push(new TestBlock("appInviteDialog", function():void {
var appInviteContent:FBAppInviteContent = new FBAppInviteContent();
appInviteContent.appLinkUrl = "";
appInviteContent.previewImageUrl = "";
ane.appInviteDialog(appInviteContent,
_appInviteDialogCallback);
}));
blocks.push(new TestBlock("gameRequestDialog", function():void {
var gameRequestContent:FBGameRequestContent = new FBGameRequestContent();
gameRequestContent.title = "";
gameRequestContent.data = "";
gameRequestContent.message = "";
gameRequestContent.objectID = "";
gameRequestContent.recipientSuggestions = [];
gameRequestContent.recipients = [];
gameRequestContent.setActionType(FBGameRequestActionType.SEND);
gameRequestContent.setFilter(FBGameRequestFilter.APP_USERS);
ane.gameRequestDialog(gameRequestContent,
true,
_gameRequestDialogCallback);
}));
blocks.push(new TestBlock("logEvent", function():void {
var event:FBEvent = FBEvent.create_ACTIVATED_APP();
ane.logEvent(event);
}));
blocks.push(new TestBlock("logOut", ane.logOut));
/**
* add ui to screen
*/
var nextY:Number = indent;
for each (var block:TestBlock in blocks) {
_scrollableContainer.addChild(block);
block.y = nextY;
nextY += block.height + indent;
}
}
private function _initCallback(...foo):void {
trace(foo);
var ane:Facebook = Facebook.instance;
/**
* setup methods
* mess with the values to mimic your own app!
*/
ane.setDefaultShareDialogMode(FBShareDialogModeIOS.AUTOMATIC,
FBShareDialogModeAndroid.AUTOMATIC);
ane.setLoginBehavior(FBLoginBehaviorIOS.NATIVE,
FBLoginBehaviorAndroid.NATIVE_WITH_FALLBACK);
ane.setDefaultAudience(FBDefaultAudience.FRIENDS);
}
private function _logInWithReadPermissionsCallback(success:Boolean, userCancelled:Boolean, error:String = null):void {
trace("logInWithReadPermissions success:" + success +
" userCancelled:" + userCancelled +
" error:" + error)
}
private function _logInWithPublishPermissionsCallback(success:Boolean, userCancelled:Boolean, error:String = null):void {
trace("logInWithPublishPermissions success:" + success +
" userCancelled:" + userCancelled +
" error:" + error)
}
private function _requestWithGraphPathCallback(graphResponse:Object):void {
}
private function _shareLinkDialogCallback(graphResponse:Object):void {
}
private function _appInviteDialogCallback(graphResponse:Object):void {
}
private function _gameRequestDialogCallback(graphResponse:Object):void {
}
}
}