HTML5 target TypeError in generated js code

Hello,

I had things working for the HTML5 target but i think i recently updated lime, haxe, openfl, etc… and i’m not sure if that is the cause of the two errors i’m getting now. I also added other code so it could be that. But basically i’m getting TypeError body is undefined.

Here is the generated code, anyone know why this might be and how to fix this.

Thanks

openfl.system.Capabilities.get_screenDPI = function() {
    if(openfl.system.Capabilities.screenDPI > 0) return openfl.system.Capabilities.screenDPI;
    var body = window.document.getElementsByTagName("body")[0];
    var testDiv = window.document.createElement("div");
    testDiv.style.width = testDiv.style.height = "1in";
    testDiv.style.padding = testDiv.style.margin = "0px";
    testDiv.style.position = "absolute";
    testDiv.style.top = "-100%";
    body.appendChild(testDiv);
    openfl.system.Capabilities.screenDPI = testDiv.offsetWidth;
    body.removeChild(testDiv);
    return openfl.system.Capabilities.screenDPI;
};

What errors are you getting?

I get this.

TypeError: body is undefined

Looks like this line doesn’t get the body element, it is undefined. I tried some older code and it doesn’t run into this error, so i’m thinking that something new i added to my src is causing this. It seems like somehow the Capabilities.get_screenDPI function is called before the html body is loaded.

var body = window.document.getElementsByTagName("body")[0];

I am also getting TypeErrors with both the latest build and the one before it, with a project that worked perfectly with html5 previously. I’m almost certain it isn’t my code causing it. As soon as I try to switch to a new screen I get the following:

TypeError: frame is undefined1 MyGameName.js:37123:3

I’m not sure how to look up the line of code causing it, since I’m not good with js coding (why I’m using openfl to start with).

It looks like something in my src is causing the order that the generated JS is executed. I’m following another issue where the ApplicationMain.config is null. So i wonder what might be causing the order to change.

Found my issue. Looks like i was trying to use Capabilities.screenDPI to initialize a static var. This caused invoking the JS function early than it was ready.
So i defaulted my var to something else and set it latter.