COMMUNITY

How to embed openfl js file into none openfl js project?

how to embed openfl js file into none openfl js project?

I have a simple js target haxe project.

   package;

import js.Lib;

import openfl.events.*;




class Main 
{
    
    static function main() 
    {
        var e:EventDispatcher;
        var k = Event.ACTIVATE;
        
        WebEventDispatch.getInstance().dispatchEvent(new Event(Event.ADDED));
        
    }
    
}




class WebEventDispatch extends EventDispatcher {
    private static var  _instance:WebEventDispatch;

    public static function getInstance():WebEventDispatch {
        if (_instance == null) {
            _instance = new WebEventDispatch();
        }

        return _instance;
    }

    public function new(target:IEventDispatcher = null) {
        super(target);

        if(_instance!=null){
            throw "webinstance eror!";
        }
        // dispatchEvent(new Event
    }
}

//////////// build.hxml
-cp src
-js bin/testopenfljs.js
-main Main
-lib openfl
///

after build .and ,there are no class was genrate.but need required

var openfl_events_EventDispatcher = require(“openfl/events/EventDispatcher”).default;

I can’t find where is EventDispatcher.js ?

how to fixed ?

OpenFL isn’t meant to be used ith -lib but using the openfl project file and build command,
see https://www.openfl.org/learn/haxelib/tutorials/displaying-a-bitmap/.

If you really have a reason to use an hxml directly, first compile using the openfl command, then check the generated hxml in the build folder to see what it is supposed to contain.

Also you’ll have better luck for openfl specific questions on https://community.openfl.org/.