0

純粋な ActionScript を使用して、Flex で PopupManager によって作成されたものと同様のウィンドウをポップアップする方法はありますか? ウィンドウがポップアップすると、背景はグレー表示されます。

4

1 に答える 1

0

これは私が最終的に得たものです:

import flash.display.DisplayObjectContainer;
import flash.display.Sprite;

import screens.GameScreen;

/**
 * The PopUpManager is used to pop up a dialog.
 * <p>
 * Usage:
 * <p>
 * <code>
 * var dialog:Sprite = ... // initialize a Sprite
 * // To pop up
 * PopUpManager.openPopUp(stage, dialog);
 * // To close the pop-up
 * PopUpManager.removePopUp();
 * </code>
 */
public final class PopUpManager
{
    private static var instance:PopUpManager;
    private static var dialog:Sprite;
    private static var curtain:Sprite;

    /**
     * @param parent The parent of this pop up window. If it is other display object other than stage,
     * only that display object will be dimmed.
     * @param dialog The dialog to be popped up.
     */
    public static function openPopUp(parent:DisplayObjectContainer, dialog:Sprite, modal:Boolean):void
    {
        if(curtain == null) {
            // Init the curtain to dim the screen or part of the screen
            curtain = new Sprite();
            curtain.graphics.beginFill(0xFFFFFF,.4);
            curtain.graphics.drawRect(0,0,parent.width/GameScreen.dpiScale,parent.width/GameScreen.dpiScale);
            curtain.graphics.endFill();
        }
        curtain.mouseEnabled = modal;
        parent.addChild(curtain);
        PopUpManager.dialog = dialog;
        curtain.addChild(dialog);
    }

    public static function removePopUp():void
    {
        curtain.removeChild(PopUpManager.dialog);
        curtain.parent.removeChild(curtain);
    }
}
于 2013-02-19T18:37:30.970 に答える