Problems when AS3 wrapper SWF loads Haxe child SWF

145 views
Skip to first unread message

Tarler

unread,
Mar 23, 2013, 7:05:08 PM3/23/13
to haxe...@googlegroups.com
Hello,

We have a SWF file created with Haxe that needs to be loaded by a 3rd party wrapper written in AS3.

The Main class in our Haxe SWF needs to be written to an interface defined in AS3.

I've tried creating a Haxe extern version of this AS3 interface using --gen-hx-classes, but this fails at runtime

TypeError: Error #1034: Type Coercion failed: cannot convert boot_9ced@b5c10b1 to IMyAS3Interface

I get the same error if I remove the extern keyword from my Haxe version of the interface

Does anyone know a way around this, please?

Thanks for any help,
James



Tom

unread,
Mar 24, 2013, 3:08:08 AM3/24/13
to haxe...@googlegroups.com
Hi!

If the Haxe-SWF was loaded with loader:flash.display.Loader, then loader.content points to the Haxe.SWF Lib.current object.
So, you can define a "variable", (or a function) in this SWF, Lib.current.mainClass = Main, then in the AS3-SWF you can get this, with loader.content.mainClass.
This must be work, I think, because the other-way is working for any variable for me.

Tarler

unread,
Jul 4, 2013, 5:53:47 PM7/4/13
to haxe...@googlegroups.com
Thanks for your reply Tom. The problem is I don't have control of the AS3 wrapper SWF so I'm unable to make changes to it to access the child Haxe SWF.

It's because the Haxe compiler adds its own boot class as the document class of the SWF, which in turn calls the static main() function on the intended document class.

I've got round this in a rather messy way by making an intermediate AS3 SWF whose document class does conform to the AS3 interface. This in turn loads my Haxe SWF and starts it up

//AS3 class
public function myInterfaceImplementation():void
{
 loader
= new Loader();
 loader
.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
 loader
.load(new URLRequest("MyHaxeSwf.swf"));
}


protected function loadComplete(e:Event):void
{
 loader
.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);

 
var content:* = loader.content;
       
/*you need to call the init method of the Haxe boot class,
        otherwise static fields of classes aren't initialised */

 content
.init();

 loader
= null;

 
var appClassObj:* = getDefinitionByName("MyHaxeApplicationClass") ;
 
var app:* = appClassObj.getInstance();


 app
.init();
}

Junjo

unread,
Aug 19, 2014, 3:19:00 AM8/19/14
to haxe...@googlegroups.com
Hello Tarler,

I'm in a similar situation to what you've explained in this thread, so I need to wrap the loading of my openfl game with a AS3 loader. I've tried this solution (thanks for sharing it), but I get a "null" access error in the content.init(); line. I see that the main method of the haxe "boot" class is executed, then the main method of the ApplicationMain class, and is there (ApplicationMain.main) where the error occurs.

Is this solution still working in the current haxe/openfl version?
There's another way to load an haxe-swf from a as3-swf?

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages