|
|
Example codeEnter the following code in the Actions panel of the FLA
file.
import com.adobe.fps;
connectBtn.enabled = false;
label.text = 'Loading Social service ...';
connectBtn.addEventListener(MouseEvent.CLICK, onConnectBtnClick);
// Step 2 - Define a configuration object. Insert your API Key below:
var conf:Object = {
APIKey: 'Put Your APIKey here',
mcRoot: root,
enabledProviders: '*'
}
// Step 3 - Load Social service
// 3.1 Create the load-parameters object
var loadParams:Object = {
services:'socialize',
callback:onServiceLoad
}
// 3.1 Load the services
fps.load(conf,loadParams);
// 3.2 Wait for the load to complete and handle failures\success
function onServiceLoad(response): void
{
if (response.hadError) {
// handle failure
label.text = 'An error has occurred while attempting to load Social service';
} else {
// successful load
label.text = '';
connectBtn.enabled = true;
}
}
function onConnectBtnClick(event: MouseEvent): void {
// Step 4 - Define parameters object:
var connectParams:Object = {
callback: onConnect,
provider: 'facebook'
};
// Step 5 - Calling the Social API method - connect:
fps.services.socialize.connect(conf, connectParams);
}
// Step 6 - Define callback function:
function onConnect(response: Object): void {
if (response.status=='OK')
{
// inject the user's nickname to the label
label.text = response.user.nickname;
// inject the user's photo to the image "source" attribute.
image.source=response.user.photoURL;
} else {
//handle errors
label.text = "An error has occurred!" + '\n' +
"Error details: " + response.statusMessage + '\n' +
"In method: " + response.operation;
}
}
|