开发者

Semi-transparency in ActionScript 3.0 shapes?

I'm trying to make a modal pop up in my Flash application, not unlike the ASP.NET version seen here.

I've already开发者_运维百科 got the dialog box made, but I'm trying to add a semi-transparent gray rectangle over everything behind the pop-up, again like the one used in ASP.NET. Is there a way to do this in ActionScript? It needs to be semi-transparent, not fully, so you can still partially see what's behind it. I'm assuming you could apply this property to a Shape class somehow, but I can't figure it out.

Thanks in advance for the help.


Use the "alpha" property of the Shape class http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#alpha


If you're using Flex, there is a convenient mx.managers.PopUpManager class that does just that. You specify the popup as modal and the background gets semi-transparent and blurred.


package
{
    import flash.display.Sprite;
    import flash.geom.Rectangle;

    public class ClickBlocker extends Sprite
    {
        public function ClickBlocker(bounds : Rectangle, blockColor : uint, blockAlpha : Number)
        {
            mouseEnabled = true;
            mouseChildren = false;
            graphics.beginFill(blockColor, blockAlpha);
            graphics.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
            graphics.endFill();
        }
    }
}

var clickBlocker = new ClickBlocker(new Rectangle(0,0,640,480),0x666666,0.25);
addChild(clickBlocker)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜