as3 _ctx是null pozirk android在app中购买ANE

时间:2013-09-06 09:04:31

标签: android actionscript-3 in-app-purchase air-native-extension

我用谷歌搜索_ctx是Null,我很惊讶没有找到与Android有关的内容。如果我们找到正确的答案,我希望这个姿势会对某人有所帮助。

以下是我正在使用的ANE的链接:https://github.com/pozirk/AndroidInAppPurchase

我不知道从哪里开始。它现在曾经不起作用。 :(

我正在尝试使用Pozirk的InAppPurchase.ane - 我之前使用过,但突然间它无法正常工作。我不确定是什么改变了。它可能是,ANE,或谷歌游戏中的东西。不确定,但现在它不工作,我继续得到这个错误:

_ctx为空。 TypeError:错误#1009:无法访问空对象引用的属性或方法。     在com.pozirk.payment.android::InAppPurchase/init()[C:\Users\blah\blah\Android\com\pozirk\payment\android\InAppPurchase.as:46]     at HereWeGo_fla :: MainTimeline / fl_MouseClickHandler()[hereWeGo_fla.MainTimeline :: frame1:97]

    import com.pozirk.payment.android.InAppPurchase;
    import com.pozirk.payment.android.InAppPurchaseEvent;
    import flash.display.MovieClip;

    /**
     * ...
     * @author Ben Barnard
     */

         var _iap:InAppPurchase;


            _iap = new InAppPurchase();

            _iap.addEventListener(InAppPurchaseEvent.INIT_SUCCESS, onInitSuccess);
            _iap.addEventListener(InAppPurchaseEvent.INIT_ERROR, onInitError);

            _iap.addEventListener(InAppPurchaseEvent.PURCHASE_SUCCESS, onPurchaseSuccess);
            _iap.addEventListener(InAppPurchaseEvent.PURCHASE_ALREADY_OWNED, onPurchaseSuccess);
            _iap.addEventListener(InAppPurchaseEvent.PURCHASE_ERROR, onPurchaseError);

            _iap.addEventListener(InAppPurchaseEvent.CONSUME_SUCCESS, onConsumeSuccess);
            _iap.addEventListener(InAppPurchaseEvent.CONSUME_ERROR, onConsumeError);

            _iap.addEventListener(InAppPurchaseEvent.RESTORE_SUCCESS, onRestoreSuccess);
            _iap.addEventListener(InAppPurchaseEvent.RESTORE_ERROR, onRestoreError);

            // Liscense Key




         function onRestoreError(e:InAppPurchaseEvent):void 
        {
            trace("Restore Error - " + e.toString());
            outputField.text = "Restore Error - " + e.toString() + e.data.toString();
        }

         function onConsumeError(e:InAppPurchaseEvent):void 
        {
            trace("Consume Error - " + e.toString());
            outputField.text = "Consume Error - " + e.toString() + e.data.toString();
        }

         function onConsumeSuccess(e:InAppPurchaseEvent):void 
        {
            trace("Consume Success - " + e.toString());
            outputField.text = "Consume Success - " + e.toString();

            // ------------------------------- THIS LINE PROMPTS THE USER TO PURCHASE THE ITEM ------------------------------- //
            _iap.purchase("android.test.purchased", InAppPurchase.TYPE_INAPP);
        }

         function onPurchaseError(e:InAppPurchaseEvent):void 
        {
            trace("Purchase Error - " + e.toString());
            outputField.text = "Purchase Error - " + e.toString();
        }

         function onRestoreSuccess(e:InAppPurchaseEvent):void
        {
            trace("Restore Success - " + e.toString());

            // ------------------------------- THIS LINE CONSUMES THE "TEST" ITEM ------------------------------- //
            _iap.consume("android.test.purchased");
        }

         function onPurchaseSuccess(e:InAppPurchaseEvent):void 
        {
            trace("Purchase Successful - " + e.data.toString());
            outputField.text = "Purchase Successful - " + e.data.toString();
        }

         function onInitError(e:InAppPurchaseEvent):void 
        {
            trace("Init Error - " + e.toString());
            outputField.text = "Init Error - " + e.toString();
        }

         function onInitSuccess(e:InAppPurchaseEvent):void 
        {
            trace("Init Success - " + e.toString());
            outputField.text = "Init Success - " + e.toString();

            // ------------------------------- THIS LINE RESTORES ALL PURCHASED ITEMS ------------------------------- //
            //_iap.restore(InAppPurchase.TYPE_INAPP);
        }




    init.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
    _iap.init("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiM0Lpjf/S5JQOh0L5c3IQNawziFTT9WeJ9fAmQl5nXJdfVnRK9+mMCnHJlKz8omt9RljlrtLpOV4iy+/KUFgtZ/SCvF+Brpk9lAEe+SbifT2mNGNKgF3tCXSHTXX2Xuq9kw1CR0bDy0Jf36LE04zBo4jYV4RcWQ66ViS2JbTEXAugG5S71z+CJXo6o5uYG/mRZlHFRJkpp1ufDFg4dp8r2ApN3RXhMv9Rl3NCcwTk3R0/rmwCc80Uy94kX7hkgeBuj/AViFZMbzYzY8YLdx80cYYHPc/ofecXmCl6OorJiBC+GiMs/vBoyjr4EGeIqfp1WdZrxeaJzMzAWPNoY4mSwIDAQAB");
}


purchase.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler_2(event:MouseEvent):void
{
    //_iap.restore(InAppPurchase.TYPE_INAPP);
    _iap.purchase("android.test.purchased", InAppPurchase.TYPE_INAPP);
}


consume.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);

function fl_MouseClickHandler_3(event:MouseEvent):void
{
    //_iap.restore(InAppPurchase.TYPE_INAPP);
    _iap.consume("android.test.purchased");
}

restore.addEventListener(MouseEvent.CLICK, rLove);

function rLove(event:MouseEvent):void
{
    //_iap.restore(InAppPurchase.TYPE_INAPP);
    _iap.restore(InAppPurchase.TYPE_INAPP);
}

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我的清单,在修补FlashBuilder 2小时之后:

1)"项目" >属性> ActionScript构建路径>原生扩展>添加ANE> "添加InAppPurchase.ane"

2)"项目" >属性> ActionScript Build Packaging>谷歌Android>原生扩展> "选择包InAppPurchase.ane"

3)... AS3代码使用应用内购买API ...

4)如果你试图在调试模式下使用它,ANE似乎会失败;应该使用导出的APK。

5)FlashBuilder>项目>出口发布版本:

  • 验证包中是否包含ANE(Native Extensions)
  • 确认您使用的是正确的签名证书。

6)将创建的APK复制到Android设备。

7)使用文件浏览器安装APK。

8)应用程序最终运行,而不是在启动时崩溃/挂起。