Hello all. I’ve been using OpenFL/Haxe for approximately 1 day But I’m experienced with Flash/AS3 and so getting up to speed has been no problem. But I have encountered an issue when trying to use the stageHeight or width. Every time I try to divide, or multiply with them, I get a crash. I suspect this might be a stupid question but I’m a bit confused as to how the math in Haxe works, and why it only seems to happen with these values. I discovered that I am apparently supposed to use Std.int while doing these operations, and while that works fine if I use a flat number, when attempting to divide or multiply the stageHeight/Width, it simply crashes.
Any help would be appreciated.
Hi there. How are you accessing
stageWidht/Height property? by
Lib.stage.stageWidth? It could be related to
null if the object is not added to displaylist.
And which kind of error do you get in debug? You only mentioned that it’s crashing (which target?). In flash you usually get a runtime error during the crash. Be good to check that.
Ah… figured it out. Turns out it was because it was returning null…(I swear I did a trace to make sure it had a value but… I guess I’m just crazy)
Your mention of the displaylist made me check if I could do it in the main file rather than in a class, and voila, it was fine. I was writing in the constructor(right term for Haxe?) which I presume means it’s attempting to access the stage before being added to it and thus can’t find it. I hooked the it up to an ADDED_TO_STAGE event and all is well
That’s what i thought. Glad you’ve figured it out.
stage.stageWidth in the constructor of the document class is okay, but other classes do need to wait until after they are added to the Stage