Copy link to clipboard
Copied
Hi, I am trying to build native extension for OS X.
After creating context, I try to call native function with "call" method, but always I have an error "The extension context does not have a method with the name ..."
In as3 code my ExtensionContext is not null, so it's okay. And in native objective-c code I have a function, which I call in as3 code.
What should I do?
Here my code.
Objective-c:
FREContext AirContext = nil;
FREObject init(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
return nil;
}
FREObject someFunction(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
FREDispatchStatusEventAsync(AirContext ,(uint8_t*) "SOME_EVENT", (uint8_t*) "some information" );
return nil;
}
void ANEContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet)
{
NSLog(@"Entering ContextInitinalizer()");
*numFunctionsToTest = 5;
FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * *numFunctionsToTest);
func[0].name = (const uint8_t*) "init";
func[0].functionData = NULL;
func[0].function = &init;
func[1].name = (const uint8_t*) "someFunction";
func[1].functionData = NULL;
func[1].function = &someFunction
// other blank functions
*functionsToSet = func;
AirContext = ctx;
FREDispatchStatusEventAsync(AirContext ,(uint8_t*) "SOME_EVENT", (uint8_t*) "some information" );
}
void ContextFinalizer(FREContext ctx) {
NSLog(@"Entering ContextFinalizer()");
NSLog(@"Exiting ContextFinalizer()");
}
void ANEInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet, FREContextFinalizer* ctxFinalizerToSet )
{
NSLog(@"Entering ExtInitializer()");
*extDataToSet = NULL;
*ctxInitializerToSet = &ContextInitializer;
*ctxFinalizerToSet = &ContextFinalizer;
NSLog(@"Exiting ExtInitializer()");
}
void ANEFinalizer(void* extData)
{
return;
}
ActionScript3:
public class MyANE extends EventDispatcher{
private static var _instance:MyANE;
private var extCtx:ExtensionContext;
public function MyANE()
{
if (!_instance)
{
if (this.isSupported)
{
extCtx = ExtensionContext.createExtensionContext("my.awesome.ane", null);
if (extCtx != null)
{
trace('context is okay'); //this trace works
extCtx.addEventListener(StatusEvent.STATUS, onStatus);
} else
{
trace('context is null.');
}
}
_instance = this;
}
else
{
throw Error('singleton');
}
}
public static function getInstance():MyANE
{
return _instance != null ? _instance : new MyANE();
}
public function get isSupported():Boolean
{
var value:Boolean = Capabilities.manufacturer.indexOf('Macintosh') > -1;
trace(value ? 'supported' : 'not supported ');
return value;
}
private function onStatus(event:StatusEvent):void
{
trace('Event', event, 'code', event.code, 'level', event.level); //this traсе does not works
}
private function test(): void
{
extCtx.call("someFunction"); //this throws error
}
XML:
<extension xmlns="http://ns.adobe.com/air/extension/3.9">
<id>my.awesome.ane</id>
<versionNumber>1.0.0</versionNumber>
<platforms>
<platform name="MacOS-x86">
<applicationDeployment>
<nativeLibrary>MyANE.framework</nativeLibrary>
<initializer>ANEInitializer</initializer>
<finalizer>ANEFinalizer</finalizer>
</applicationDeployment>
</platform>
</platforms>
</extension>
And this script Im using for build ANE:
mv ../as3/bin/MyANE.swc .
unzip MyANE.swc
mv library.swf mac/
rm catalog.xml
rsync -a ../Obective-C/ANE/Build/Products/Debug/ANE.framework/ mac/ANE.framework/
adt -package -target ane MyANE.ane extension.xml -swc MyANE.swc -platform MacOS-x86 -C mac .
mv MyANE.ane ~/Work/_Projects/test/libs-ane/
Copy link to clipboard
Copied
I haven't done Objective C in a long time, but if I'm not mistaken, it requires the semicolon to terminate a line of code. The line containing "func[1].function = &someFunction" does not have that termination and since that is the function you are trying to execute, maybe that is the source of the error.
Copy link to clipboard
Copied
Sorry, I missed it, when edited message. Code is valid (before building ANE, I need to build Objectve-C code, so it's checked for validity)
Copy link to clipboard
Copied
Hey, Even i am facing the same issue but for Android platform.