Search code examples
c++actionscript-3airair-native-extension

AIR Native Extensions "The extension context does not have a method with the name"


I am attempting to make an AIR Native Extension and after successful compilation of all components, Flash Builder 4.6 logs "Error #3500: The extension context does not have a method with the name...".

Here's the C++ code for the native DLL:

#include "stdafx.h"
#include "TestANE.h"

#include "FlashRuntimeExtensions.h"

#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>

using namespace std;

FREObject isSupported(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
    FREObject result;

    uint32_t isSupportedSwitch = 1;
    FRENewObjectFromBool(isSupportedSwitch, &result);

    return result;
}

FREObject getString(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
    FREObject result;

    const char *testString = "Hello World from C++!";
    FRENewObjectFromUTF8(strlen(testString)+1, (const uint8_t *) testString, &result);

    return result;
}

void taneContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctions, const FRENamedFunction** functions) { 
    *numFunctions = 2;
    FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * (*numFunctions));

    func[0].name = (const uint8_t*) "isSupported";
    func[0].functionData = NULL;
    func[0].function = &isSupported;

    func[1].name = (const uint8_t*) "getString";
    func[1].functionData = NULL;
    func[1].function = &getString;

    *functions = func;
}

void taneContextFinalizer(FREContext ctx) {
    return;
}

void taneInitializer(void** extData, FREContextInitializer* ctxInitializer, FREContextFinalizer* ctxFinalizer) { 
    *ctxInitializer = &taneContextInitializer;
    *ctxFinalizer = &taneContextFinalizer;
}

void taneFinalizer(void* extData) {
    return;
}

Here's the code for the ActionScript 3 interface:

package com.tests.TestANE {
    import flash.events.EventDispatcher;
    import flash.events.IEventDispatcher;
    import flash.external.ExtensionContext;

    public class TestANE extends EventDispatcher {

        private var _ExtensionContext:ExtensionContext;

        public function TestANE(target:IEventDispatcher=null) {

            this._ExtensionContext = ExtensionContext.createExtensionContext("com.tests.TestANE", null);

            super(target);
        }

        public function isSupported():Boolean {
            return _ExtensionContext.call("isSupported") as Boolean;
        }

        public function getString():String {
            return _ExtensionContext.call("getString") as String;
        }

        public function dispose():void {
            this._ExtensionContext.dispose();
        }
    }
}

Any help in solving this issue would be appreciated.


Solution

  • I've solved this problem. I am not completely certain how as I started with another ANE project and built from there. I suspect however that the problem had to do with wrong package names in the ActionScript part of the code and the extension descriptor.