[HTML5] Loading external modules in OpenFL


Is there a way to load code stored in an external .js file by another .js file? For example, in Flash I had 2 swf files, loader.swf and game.swf. loader.swf would load game.swf inside itself by means of the Loader and URLRequest classes and then would create and attach to stage instances of classes implemented in game.swf.

Are there ways to recreate a similar approach in OpenFL when targeting HTML5?


I believe that openfl.display.Loader will execute code if the target file is JavaScript. This should not be necessary.

Consider that all JavaScript is executing at once. We have set our exports in Lime to wrap your code in a closure so that it is isolated from the global “namespace” in JavaScript, however a direct reference to/from other executing JavaScript code is all that is required to connect the two. I am not entirely sure what would happen if you loaded two distinct OpenFL projects on the same HTML page and tried adding children from one to the other. There is a chance that it would have some trouble if you did not removeChild first because the stage reference probably is not expecting to be moved from one stage to another.

OpenFL on Flash Player uses a preloader that loads in advance of the rest of the game code. HTML5 (currently) loads all game code, then uses a preloader to load any other file assets.

1 Like

What would happen, @singmajesty, if you compile to swf and then prep it as an asset using openfl process game.swf? Does any code get stripped out?

openfl process will attempt to extract bitmaps, movie clips, shapes and buttons. It has a basic ActionScript interpreter

1 Like