Well I’ll be damned:
First, the build doesn’t throw anything like you say, it actually compiles and launches just fine. It’s at the main window when it freezes or crashes.
Second, I have quite a mess of code already as you might imagine, as in classes in their respective files, a project package structure, etc. so posting here my code would be quite messy.
Third, so I go and start an empty project with -just- the piece I’m having problem with in order to post it here, and guess what, NOW it works as well as it should (doesn’t hang).
import flash.display.Sprite;
import flash.events.Event;
import flash.Lib;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.Assets;
enum FadeStates
{
FADE_IN;
WAIT;
FADE_OUT;
END;
}
class Main extends Sprite
{
var inited:Bool;
var fadeStep:FadeStates;
var fadeRate:Float;
var myBitmap:Bitmap;
/* ENTRY POINT */
function resize(e)
{
if (!inited) init();
// else (resize or orientation change)
}
function init()
{
if (inited) return;
inited = true;
// (your code here)
// Stage:
// stage.stageWidth x stage.stageHeight @ stage.dpiScale
// Assets:
// nme.Assets.getBitmapData("img/assetname.jpg");
addEventListener(Event.ENTER_FRAME, update);
var bitData = Assets.getBitmapData("img/hello.PNG");
myBitmap = new Bitmap(bitData);
Lib.current.stage.addChild(myBitmap);
myBitmap.x = (stage.stageWidth - myBitmap.width) / 2;
myBitmap.y = (stage.stageHeight - myBitmap.height) / 2;
myBitmap.alpha = 0.0;
fadeStep = FADE_IN;
fadeRate = 0.025;
}
private function carryOn():Void
{
fadeStep = FADE_OUT;
}
private function update(eventReceived:Event):Void
{
switch(fadeStep)
{
case FADE_IN:
(myBitmap.alpha >= 0.999) ? fadeStep = WAIT : myBitmap.alpha += fadeRate;
case WAIT:
haxe.Timer.delay(carryOn, 4000);
case FADE_OUT:
(myBitmap.alpha <= 0) ? fadeStep = END : myBitmap.alpha -= fadeRate;
case END:
Lib.current.stage.removeChild(this);
}
}
/* SETUP */
public function new()
{
super();
addEventListener(Event.ADDED_TO_STAGE, added);
}
function added(e)
{
removeEventListener(Event.ADDED_TO_STAGE, added);
stage.addEventListener(Event.RESIZE, resize);
#if ios
haxe.Timer.delay(init, 100); // iOS 6
#else
init();
#end
}
public static function main()
{
// static entry point
Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
Lib.current.addChild(new Main());
}
}
My project code isn’t really different, the only thing I did not replicate is setting up the stage background color and a couple of things that extend the Sprite class to have some methods of its own in order to unload/load itself to facilitate me a “scenario/scenes” workflow.
What could interfere with accessing Bitmap.alpha? I’ve set up a dozen debug traces around and it hangs riiiiight before I do bitmap.alpha += newAlphaFloat, as if it didn’t even get past that line.