Haxe Forum > loading javascript-code
-
Stefan von der Krone May 15 at 17:12
Hello there,
I'm working on a solution to load javascript-modules dynamically via haxe.Http. My goal is to implement a similar solution as I would develop in AS3.
In developing such a solution in Haxe for Flash, the problem is the underlying Boot-Class and the main()-method of each SWF-File. Unlike in AS3 where I can let the module implement an interface and everything is just fine, in Haxe my idea is to use something like a ModuleFactory, where every loaded module registers itself to tell the main-application, that it's loaded and ready to work. In my case, the ModuleFactory is a Singleton. I thought, it could work the same way in Flash as well as in JavaScript.
The Problem with JavaScript is, that every Object used by both, the main-application and the module, will be overwritten by the new module's code. My naive solution is to delete all duplicated code in the module's js-file. Another approach could be to check the loaded js-file and delete duplicated code at runtime before inserting it in the DOM.
Is there any solution, that can handle this problem more comfortable? Or is there a better idea? Maybe a compile-argument to exclude certain classes.Btw: the compile-argument "--js-modern" leads to new problems, because every application works in its own anonymous object, as I could see. At least at couldn't find the created objects with Firebug^^
Thank you very much :)