StablexUI
StablexUI copied to clipboard
Alert Dialog
http://techblogon.com/wp-content/uploads/2013/02/alert-dialog-in-android.png
This is not so hard to do it yourself. I created a dialog.xml such as:
<?xml version="1.0" encoding="UTF-8"?>
<Floating name="'dialog'" padding="20" skinName="'dialog'" childPadding="20" on-free="exit();">
<Text text="text" format-align="flash.text.TextFormatAlign.CENTER" />
<HBox childPadding="20">
<Button text="buttonText" on-click="$this.getParent('dialog').free();" />
</HBox>
</Floating>
And to open it with a semi-transparent background covering the screen:
private var lightbox: Sprite;
private var dialog: Floating;
public function showLightbox() {
if (lightbox == null) {
lightbox = new Sprite();
}
var gfx = lightbox.graphics;
gfx.clear();
gfx.beginFill(0x000000, 0.8);
gfx.drawRect(0, 0, stageWidth, stageHeight);
gfx.endFill();
addChild(lightbox);
}
public function hideLightbox() {
removeChild(lightbox);
lightbox = null;
}
public function error(msg: String) {
showDialog(msg, function() {
#if !flash
Sys.exit(1);
#end
});
}
public function showDialog(text: String, buttonText: String = "Ok",
cancelText: String = "Cancel", f: Void -> Void = null) {
var exit = function() {
hideLightbox();
if (f != null) {
f();
}
}
dialog = UIBuilder.buildFn('Assets/UI/dialog.xml')();
showLightbox();
dialog.show();
onStageResize(null);
}
public function onStageResize ( e: Event ) {
if (lightbox != null) {
showLightbox();
}
if (dialog != null) {
dialog.left = (stageWidth - dialog.width) / 2;
dialog.top = (stageHeight - dialog.height) / 2;
}
}