TUTORIALS

How to authenticate to the Game Center

  /* Get a GameCenterManager instance from Snapdragon API. */
  var gcManager:SDGameCenterManager = Snapdragon.instance.gameCenterManager;

  gcManager.addEventListener(SDAuthenticationEvent.AUTHENTICATION_COMPLETE, authComplete);
  gcManager.addEventListener(SDAuthenticationEvent.AUTHENTICATION_ERROR, authError);

  /* You should check if the game center is available on the device before doing anything. */
  if(gcManager.isGameCenterAvailable()){
    /* The first step of using the game center is the authentication of the user. */
    gcManager.gameCenterAuthentication();
  }
  
  public function authComplete(event:SDAuthenticationEvent):void{
 	 /* Get the username of the authenticated user. */
 	 var name:String = gcManager.getLocalPlayer().alias;
  }
    

Using the achievement system

/* Listening to the events of the game center achievements */
gcManager.addEventListener(SDAchievementEvent.ACHIEVEMENT_PROGRESS_ERROR, achievementProgressError);
gcManager.addEventListener(SDAchievementEvent.ACHIEVEMENT_PROGRESS_COMPLETE, achievementProgressComplete);
gcManager.addEventListener(SDAchievementEvent.ACHIEVEMENT_SUBMIT_ERROR, achievementSubmitError);
gcManager.addEventListener(SDAchievementEvent.ACHIEVEMENT_SUBMIT_COMPLETE, achievementSubmitComplete);
gcManager.addEventListener(SDAchievementEvent.ACHIEVEMENT_RESET_ERROR, achievementResetError);
gcManager.addEventListener(SDAchievementEvent.ACHIEVEMENT_RESET_COMPLETE, achievementResetComplete);
gcManager.addEventListener(SDAchievementEvent.ACHIEVEMENT_VIEW_CLOSED, achievementViewClosed);

/* It is possible to show the native achievement view from the application, but it should be paused while the view is open. */
gcManager.showAchievements();

/* To get the progress of the achievements of the current user, it should be requested */
gcManager.achievementRequest();

/* The result of the request comes with the ACHIEVEMENT_PROGRESS_COMPLETE event in the achievements vector. */
public function achievementProgressComplete(event:SDAchievementEvent):void{
	for each(var achievement:SDAchievement in event.achievements){
		trace(achievement.identifier);
	}
}

/* The submission of an achievement is possible with the id of it given in the itunes connect, a progress of the completion and if the banner of completion should be displayed or not. */
gcManager.submitAchievement("test_achievement_01", 100, true);

/* There is the possibility to clear the progress of the achievements of the current user. It can be helpful in the testing of the application. */
gcManager.resetAchievements();
    

Using the leaderboard system

/* Listening to the events of game center leaderboards */
gcManager.addEventListener(SDLeaderboardEvent.LEADERBOARD_LIST_ERROR, leaderboardListError);
gcManager.addEventListener(SDLeaderboardEvent.LEADERBOARD_LIST_COMPLETE, leaderboardListComplete);
gcManager.addEventListener(SDLeaderboardEvent.LEADERBOARD_SCORE_REPORT_ERROR, leaderboardScoreReportError);
gcManager.addEventListener(SDLeaderboardEvent.LEADERBOARD_SCORE_REPORT_COMPLETE, leaderboardScoreReportComplete);
gcManager.addEventListener(SDLeaderboardEvent.LEADERBOARD_SCORE_REQUEST_ERROR, leaderboardScoreRequestError);
gcManager.addEventListener(SDLeaderboardEvent.LEADERBOARD_SCORE_REQUEST_COMPLETE, leaderboardScoreRequestComplete);
gcManager.addEventListener(SDLeaderboardEvent.LEADERBOARD_VIEW_CLOSED, leaderboardViewClosed);

/* The application is capable to get the list of the leaderboards from the game center. */
gcManager.leaderboardListRequest();

/* The result of the request contains the list of the leaderboards in a vector. */
public function leaderboardListComplete(event:SDLeaderboardEvent):void{
	for each(var leaderboard:SDLeaderboard in event.leaderboards){
		trace(leaderboard.title + " - " + leaderboard.category);
	}
}

/* To report the result of the current user, the id of the leaderboard in the itunes connect and the users score should be given. */
gcManager.reportScoreForLeaderboard("test_leaderboard", 100);

/* It is possible to show the native leaderboard view, but it must be specified, which leaderboard and which time scope should be displayed. */
gcManager.showLeaderboard("test_leaderboard", SDLeaderboard.TIME_SCOPE_ALL_TIME);
    

iAd network

/* Get an AdManager instance from Snapdragon API. The advertisments start loading immediately.*/
var adManager:SDAdManager = adManager = Snapdragon.instance.adManager;

/* While the user watches the content of the advertisment, the game should be paused. */
adManager.addEventListener(SDAdEvent.BANNER_AD_ACTION_STARTED, bannerAdActionStarted);
adManager.addEventListener(SDAdEvent.BANNER_AD_ACTION_FINISHED, bannerAdActionFinished);
adManager.addEventListener(SDAdEvent.ADMOB_BANNER_AD_ACTION_STARTED, bannerAdMobActionStarted);
adManager.addEventListener(SDAdEvent.ADMOB_BANNER_AD_ACTION_FINISHED, bannerAdMobActionFinished);
adManager.addEventListener(SDAdEvent.FULL_SCREEN_VIEW_AD_ACTION_FINISHED, fullScreenAdActionFinished);
adManager.addEventListener(SDAdEvent.ADMOB_FULL_SCREEN_VIEW_AD_ACTION_FINISHED, fullScreenAdMobActionFinished);

/* When the orientation of the screen changes, the ad banner should be resized and repositioned. */
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orientationChange);

/* Place a full screen ad in the application. It can only be used on iPad with iOS 4.3 and greater, or iPhone with iOS 7. If the device don't support it, it won't be displayed but there won't be any event or error about it. It will be displayed only, when it is loaded. */
adManager.addAdFullScreenView();

/* Place a full screen ad in the application. It can be used on iPhone also with iOS 4.3 and greater. Do not use iAd and AdMob at the same time. */
adManager.addAdMobFullScreenView("unit_id");

/* Place the ad banner in the application. The banner starts loading at the instantiation of the SDAdManager, if it is added before the loading of it is complete, it will be displayed after it got loaded. */
adManager.addAdBannerView(orientation, SDAdManager.BANNER_POSITION_BOTTOM);

adManager.addAdMobBannerView("unit_id", orientation, SDAdManager.BANNER_POSITION_TOP);

/* If the ad banner is no more needed, it should be removed. It is the same for iAd and AdMob banner. */
adManager.removeAdBannerView();

public function orientationChange(event:StageOrientationEvent):void{
	if(event.afterOrientation == StageOrientation.ROTATED_LEFT || event.afterOrientation == StageOrientation.ROTATED_RIGHT){
		adManager.changeOrientation(Snapdragon.SCREEN_ORIENTATION_LANDSCAPE);
	}else{
		adManager.changeOrientation(Snapdragon.SCREEN_ORIENTATION_PORTRAIT);
	}
}
    

App store

/* Get an StoreManager instance from Snapdragon API. */
var storeManager:SDStoreManager = storeManager = Snapdragon.instance.storeManager;

storeManager.addEventListener(SDStoreEvent.PRODUCT_IDENTIFIER_VALIDATION_COMPLETE, storeValidationComplete);
storeManager.addEventListener(SDStoreEvent.PRODUCT_PURCHASING, purchasing);
storeManager.addEventListener(SDStoreEvent.PRODUCT_PURCHASED, purchased);
storeManager.addEventListener(SDStoreEvent.PRODUCT_PURCHASE_RESTORED, restored);
storeManager.addEventListener(SDStoreEvent.PRODUCT_PURCHASING_FAILED, purchaseFailed);

/* Collect the product identifiers into a vector for validation. Validation is an inavoidable step, before you can use the store. */
var identifiers:Vector.<String> = new Vector.<String>();

identifiers.push("test_non_consumable");
identifiers.push("test_consumable");

/* Start the validation. The second parameter is the secret to store the already purchased products on the phone. */
storeManager.validateProductIdentifiers(identifiers, "com.app.id");


public function storeValidationComplete(event:SDStoreEvent):void{
	var response:SDResponse = event.response;

	for(var i = 0; i < response.products.length; ++i){
	}

	/* There should not be any invalid identifier. If there is any, you should check the settings on itunes connect. */
	for(i = 0; i < response.invalidIdentifiers.length; ++i){
	}
}

/* There should be a button in the application, that allows the user to restore the earlier purchases from the app store. */
storeManager.restoreTransactions();

/* Purchase the product given by its product identifier. */
storeManager.purchaseNonConsumableProduct("test_non_consumable");
storeManager.purchaseConsumableProduct("test_consumable", 1);
    

Notification Center

/* Get a notification manager instance from Snapdragon API. */
var notificationManager:SDNotificationManager = Snapdragon.instance.notificationManager;

notificationManager.addEventListener(SDNotificationEvent.NOTIFICATION_RECEIVED, notificationReceived);

/* Set the badge number of the notification. */
notificationManager.applicationBadgeNumber = 1;

public function addNotification(event:MouseEvent):void{
	/* Create an SDLocalNotification object. */
	var date:Date = new Date();
	var notification:SDLocalNotification = new SDLocalNotification("test_01", "Test notification", date);

	/* Alert action will be transformed into lowercase. */
	notification.alertAction = "view details";
	notification.badgeNumber = 1;

	/* Initiate the notification. */
	notificationManager.addLocalNotification(notification);
}

public function cancelNotification(event:MouseEvent):void{
	/* Cancel the previously created notification. */
	notificationManager.cancelLocalNotification("test_01");
}

public function cancelAllNotification(event:MouseEvent):void{
	/* Cancel all of the previously created notifications. */
	notificationManager.cancelAllLocalNotifications();
}
    

Social Center

/* Get a social manager instance from Snapdragon API. */
var socialManager:SDSocialManager = Snapdragon.instance.socialManager;

socialManager.addEventListener(SDFacebookEvent.FACEBOOK_POST_CANCELED_BY_USER, facebookPostCanceled);
socialManager.addEventListener(SDFacebookEvent.FACEBOOK_POST_PERFORMED_BY_USER, facebookPostPerformed);
socialManager.addEventListener(SDFacebookEvent.TWITTER_POST_CANCELED_BY_USER, twitterPostCanceled);
socialManager.addEventListener(SDFacebookEvent.TWITTER_POST_PERFORMED_BY_USER, twitterPostPerformed);

public function postTextToFacebook(event:MouseEvent):void{
	/* Post the text. */
	socialManager.postToFacebook("Test Post");
}

public function postImageToFacebook(event:MouseEvent):void{
	/* Create a bitmap from the image to post. */
	var data:BitmapData = new BitmapData(1024, 1024);
	var postImage:PostImage = new PostImage();
	
	data.draw(postImage);
	
	var image:Bitmap = new Bitmap(data);
	
	/* Post the image and the text to it. */
	socialManager.postImageToFacebook("Test Image", image);
}

public function postLinkTextToFacebook(event:MouseEvent):void{
	/* Post the text with the link. */
	socialManager.postToFacebook("Test Post", "http://snapdragon.flashplusplus.net");
}

public function postTextToTwitter(event:MouseEvent):void{
	/* Post the text. */
	socialManager.postToTwitter("Test Post");
}

public function postImageToTwitter(event:MouseEvent):void{
	/* Create a bitmap from the image to post. */
	var data:BitmapData = new BitmapData(1024, 1024);
	var postImage:PostImage = new PostImage();
	
	data.draw(postImage);
	
	var image:Bitmap = new Bitmap(data);
	
	/* Post the image and the text to it. */
	socialManager.postImageToTwitter("Test Image", image);
}

public function postLinkTextToTwitter(event:MouseEvent):void{
	/* Post the text with the link. */
	socialManager.postToTwitter("Test Post", "http://snapdragon.flashplusplus.net");
}