Created
March 5, 2014 15:24
-
-
Save jgranick/9369381 to your computer and use it in GitHub Desktop.
Basic IAP Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import extension.iap.IAP; | |
import extension.iap.IAPEvent; | |
import flash.display.Sprite; | |
class Main extends Sprite { | |
public function new () { | |
super (); | |
if (IAP.available) { | |
IAP.addEventListener (IAPEvent.PURCHASE_INIT, IAP_onInitSuccess); | |
IAP.addEventListener (IAPEvent.PURCHASE_INIT_FAILED, IAP_onInitFailure); | |
IAP.initialize ("your store key"); | |
} | |
} | |
private function IAP_onInitFailure (event:IAPEvent):Void { | |
trace ("Could not initailize IAP"); | |
} | |
private function IAP_onInitSuccess (event:IAPEvent):Void { | |
IAP.addEventListener (IAPEvent.PURCHASE_SUCCESS, IAP_onPurchaseSuccess); | |
IAP.addEventListener (IAPEvent.PURCHASE_FAILURE, IAP_onPurchaseFailure); | |
IAP.addEventListener (IAPEvent.PURCHASE_CANCEL, IAP_onPurchaseCancel); | |
IAP.purchase ("your product key"); | |
} | |
private function IAP_onPurchaseCancel (event:IAPEvent):Void { | |
trace ("User cancelled purchase"); | |
} | |
private function IAP_onPurchaseFailure (event:IAPEvent):Void { | |
trace ("Could not purchase item"); | |
} | |
private function IAP_onPurchaseSuccess (event:IAPEvent):Void { | |
trace ("Success!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment