StablexUI icon indicating copy to clipboard operation
StablexUI copied to clipboard

Alert Dialog

Open ejazasghar opened this issue 12 years ago • 1 comments

http://techblogon.com/wp-content/uploads/2013/02/alert-dialog-in-android.png

ejazasghar avatar Jul 11 '13 16:07 ejazasghar

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;
        }
    }

arsfeld avatar Aug 23 '13 17:08 arsfeld