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 回答