How to access Main class in Flash (SWF) target

When I generate SWF as my target haxe adds extra code to SWF that hides my main document class

Screen from decompiled SWF

and I want to be able to load that swf as content in my AIR app and communicate with my Main class via Interface.

How can I do that?

According to:

I believe you can add a define called “haxe-boot” (like <define name="haxe-boot" if="flash" /> to project.xml) to make the boot class called “haxe” instead of using the generated name. Perhaps this will help?

This will solve part of the problem, big thanks but how to call some public function from AIR that is inside Main class.

Can you use getDefinitionByName then reference it dynamically?

Yup, this works and also I can just iterate using getChildAt() BUT

and this is totally strage, when I use Loader class in AS3 when I create clean AS project in Animate CC and load haxe swf it is OK everything works fine but when I load haxe swf in FlashDevelop using same loader class I get strange error when I try to addChild(loder.content);

TypeError: Error #1006: hasField is not a function.
at lime.ui::Window()
at openfl.display::Window()
at openfl.display::Application/createWindow()
at lime._internal.backend.flash::FlashApplication()[C:\Development\HaxeToolkit\haxe\lib\lime\7,3,0\src\lime\_internal\backend\flash\FlashApplication.hx:25]
at lime.app::Application()
at openfl.display::Application()
at ApplicationMain$/create()[E:\dragongame\bin\flash\haxe\ApplicationMain.hx:31]
at ApplicationMain$/main()[E:\dragongame\bin\flash\haxe\ApplicationMain.hx:25]
at boot_b45e/init()[E:\NowaEra\dragongame\?:1]
at flash::Boot/start()
at flash::Boot/doInitDelay()
at flash.display::DisplayObjectContainer/addChild()
at flash.display::Stage/addChild()
at informatykaKlasa3.viewSection::ViewSectionGame/onLoadComplete()[E:\klasa3games\src\informatykaKlasa3\viewSection\ViewSectionGame.as:123]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_completeHandler()[E:\klasa3games\src\com\greensock\loading\core\LoaderCore.as:399]
at com.greensock.loading::SWFLoader/_completeHandler()[E:\klasa3games\src\com\greensock\loading\SWFLoader.as:748]

What can cause that?

Case solved beware of PNGEncoder2.swc it has problem with loaded haxe SWFs. It was present in project that load haxe swf resources created by me.

1 Like