as3 _ctx is null pozirk android in app purchases ANE

746 Views Asked by At

I googled _ctx is Null and I was shocked to find nothing relating to Android. I am hoping this pose will help someone if we find the right answer.

Here is a link to the ANE I am using: https://github.com/pozirk/AndroidInAppPurchase

I have no idea where to go from here. It once worked now its not. :(

I am trying to use Pozirk's InAppPurchase.ane - which I have used before but suddenly its not working. I am not sure what changed. It may be, the ANE, or something in google play. Not sure but now its not working and I keep on getting this error:

_ctx is null. TypeError: Error #1009: Cannot access a property or method of a null object reference. at 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

There are 2 best solutions below

3
On
0
On

My checklist, after tinkering FlashBuilder for 2 hours:

1) "project" > Properties > ActionScript Build Path > Native Extensions > Add ANE > "add InAppPurchase.ane"

2) "project" > Properties > ActionScript Build Packaging > Google Android > Native Extensions > "select package InAppPurchase.ane"

3) ... AS3 code uses the in-app-purchase API ...

4) The ANE seems to fail if you try to use it in debug mode; an exported APK should be used instead.

5) FlashBuilder > Project > Export Release Build:

  • Verify that the ANE is included in the package (Native Extensions)
  • Verify that your are using the correct signing certificate.

6) Copy the created APK to the Android device.

7) Install the APK using a file explorer.

8) The app finally runs, instead of crashing/hanging at startup.