In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Alert message window

Usage:
Init:
 * Alert.init(stage);
     OR
 * Alert.out("mtMsg","Title",stage);

print out messages:
 * Alert.out("MyMsg","Alert Title");


 * Compressed version included *
Get Adobe Flash player
by WLAD 18 Jul 2013
/**
 * Copyright WLAD ( http://wonderfl.net/user/WLAD )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/46jP
 */

package
{
    import flash.events.Event;
    import flash.display.Sprite;
    import com.bit101.components.*;
    
    public class Main extends Sprite 
    {
        public function Main()
        {
            if(stage) init();
            else this.addEventListener(Event.ADDED_TO_STAGE,init); } private function init(e:Event = null):void {
            removeEventListener(Event.ADDED_TO_STAGE,init);    
            
            //entery point...
                
                
            var p:Panel = new Panel(this);
            p.width = p.height = 465;    
                            
                
            //init alert 
            Alert.out("Alert init complete", "WonderFL@Info",stage);
            // or like this : Alert.init(stage); 
            
            addChildren();
        }
        
        
        private function addChildren():void
        {    
            var b:PushButton = 
            new PushButton(this, 5, 5, "Alert some stuff",function(e:Event):void
            {
                // ***********
                // EXAMPLE - 1
                Alert.out("Fact #32: YOLO_my_SWAG and SWAG_my_YOLO are the most commune COD players names.");                
                
                
            }); b.scaleX = b.scaleY = 2; b = 
            new PushButton(this, 5, 55, "Custome Title",function(e:Event):void
            {
                // ***********
                // EXAMPLE - 2
                Alert.out("This is an alerting text! \n\n News and shit,.. this is an alerting text! news and shit,.. "
                ,"This is a title... NOBODY CARES!");                
                
                
            }); b.scaleX = b.scaleY = 2; b = 
            new PushButton(this, 5, 105, "Multiple alerts: queue",function(e:Event):void
            {
                // ***********
                // EXAMPLE - 3
                Alert.out("message 1");
                Alert.out("message 2");
                Alert.out("message 3");
                Alert.out("message almost there...");
                Alert.out("10000 more to go...");                
                Alert.out("...");
                Alert.out("message 99999 (I could be fucked writing a loop)");
                Alert.out("Done!");                
                
                
            }); b.scaleX = b.scaleY = 2;
        }



    }
}

// Custome style
Style.BACKGROUND = 0x444444;
Style.BUTTON_FACE = 0x666666;
Style.INPUT_TEXT = 0xBBBBBB;
Style.LABEL_TEXT = 0xCCCCCC;
Style.PANEL = 0x666666;
Style.PROGRESS_BAR = 0x666666;

import com.bit101.components.Label;
import com.bit101.components.PushButton;
import com.bit101.components.Style;
import com.bit101.components.Window;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

//Compressed version @author http://wonderfl.net/user/Vladik
//class Alert extends Window { private static var locked:Boolean = true; private static var instance:Alert = null; private static var queue:Vector.<String>; public static function init(stage:Stage):void { if (instance) error(2); locked = false; queue = new Vector.<String>(); instance = new Alert(stage); locked = true; } public static function out(massage:String, title:String = "Alert", stage:Stage = null):void { if (!instance) { if (!stage) error(1); else init(stage); } if (instance.visible) { queue.push(massage, title); instance.alertQueue = queue.length / 2; } else instance.out(massage, title); } internal function set alertQueue(value:int):void {    title = titleBackUp; if (value == 0) return; title += " - Extra " + value.toString() +" alerts will be displayed."; } public static function changeSize(w:Number, h:Number):void { instance.setSize(w, h); } private var _format:TextFormat; internal var text:Label; internal var stageLock:Sprite; internal var stageRef:Stage; internal var ok:PushButton; internal var titleBackUp:String; internal var massage:TextField; public function Alert(stage:Stage) {    if (locked) error(0); stageRef = stage; super(); visible = false; setSize(300, 120); draggable = true; hasCloseButton = true; hasMinimizeButton = false; } public function out(msg:String, title:String = "Alert"):void {    titleBackUp = title; massage.text = msg; this.title = title; massage.width = _width - 10; massage.height = massage.textHeight + 10; height = titleBar.height + ok.height + 15 + massage.height; ok.x = _width / 2 - ok.width / 2; ok.y = _height - titleBar.height - ok.height - 5; y = stageRef.stageHeight / 2 - this.height / 2; if (stage) return; stageRef.addChild(stageLock); stageRef.addChild(this); stageLock.visible = this.visible = true; stageLock.graphics.clear(); stageLock.graphics.beginFill(0, .7); stageLock.graphics.drawRect(0, 0, stageRef.stageWidth, stageRef.stageHeight); stageLock.graphics.endFill(); x = stageRef.stageWidth / 2 - this.width / 2; } override protected function onClose(event:MouseEvent):void { if (queue.length > 0) { out(queue.shift(), queue.shift()); alertQueue = queue.length / 2; return; } super.onClose(event); stageRef.removeChild(this); stageRef.removeChild(stageLock); stageLock.visible = this.visible = false; } override protected function addChildren():void { super.addChildren(); _format = new TextFormat(Style.fontName, Style.fontSize, Style.LABEL_TEXT); massage = new TextField(); massage.x = 5; massage.y = 5; massage.height = _height; massage.embedFonts = Style.embedFonts; massage.multiline = true; massage.wordWrap = true; massage.selectable = true; massage.defaultTextFormat = _format;    _panel.addChild(massage); stageLock = new Sprite(); stageLock.visible = false; ok = new PushButton(_panel, 0, 0, "OK", onClose); ok.width = 50; } private static function error(level:int = 0):void { var nl:String = "\n * "; var msg:String = ""; switch(level) { case 0:msg = "This class is not designed" + nl + "to be used as a constractor." + nl + "Use Alert.out('your massage'); to" + nl + "display alert pop up on stage." + nl + "Or its also possible to init" +nl + "using the out() function if the" + nl + "out(msg, title, 'stage') < - stage" + nl + "variable is not equal to null"; break; case 1: msg = "Use Alert.init(stage) before" + nl + "using Alert.out() function."; break; case 2: msg = "Can not use Alert.init()" + nl + "function more then 1 times."; break; }    throw new Error(msg, level); } }

//!!! Don't forget the imports above!!!






/**
 * ...
 * @author http://wonderfl.net/user/Vladik
*/ 
class Alert extends Window 
{
    private static var locked:Boolean = true;
    
    private static var instance:Alert = null;
    
    private static var queue:Vector.<String>;
    
    public static function init(stage:Stage):void
    {
        if (instance) error(2);
        
        locked = false;
        
        queue = new Vector.<String>();
        
        instance = new Alert(stage);
        
        locked = true;
    }
    public static function out(massage:String, title:String = "Alert", stage:Stage = null):void
    {
        if (!instance) {
            if (!stage) error(1);
            else init(stage);
        }
        
        if (instance.visible) 
        {
            queue.push(massage, title);
            instance.alertQueue = queue.length / 2;
        }
        else instance.out(massage, title);
    }
    
    internal function set alertQueue(value:int):void 
    {
        title = titleBackUp;
        
        if (value == 0) return;
        
        title += " - Extra " + value.toString() +
        " alerts will be displayed.";
    }
    
    public static function changeSize(w:Number, h:Number):void
    {
        instance.setSize(w, h);
    }
    
    private var _format:TextFormat;
    
    internal var text:Label;
    internal var stageLock:Sprite;
    internal var stageRef:Stage;
    internal var ok:PushButton;
    internal var titleBackUp:String;
    internal var massage:TextField;
    
    public function Alert(stage:Stage) 
    {    
        if (locked) error(0);
        
        stageRef = stage;
        
        super();
        
        visible = false;
        
        setSize(300, 120);
        
        draggable = true;
        hasCloseButton = true;
        hasMinimizeButton = false;
    }
    
    public function out(msg:String, title:String = "Alert"):void
    {    
        titleBackUp = title;
        massage.text = msg;
        this.title = title;
        
        massage.width = _width - 10;
        massage.height = massage.textHeight + 10
        
        height = titleBar.height + 
        ok.height + 15 + 
        massage.height;
        
        ok.x = _width / 2 - ok.width / 2;
        ok.y = _height - titleBar.height - ok.height - 5;
        
        y = stageRef.stageHeight / 2 - this.height / 2;
        
        if (stage) return;
        
        stageRef.addChild(stageLock);
        stageRef.addChild(this);
        stageLock.visible = this.visible = true;
        
        stageLock.graphics.clear();
        stageLock.graphics.beginFill(0, .7);
        stageLock.graphics.drawRect(0, 0,
            stageRef.stageWidth, stageRef.stageHeight);
        stageLock.graphics.endFill();
        
        x = stageRef.stageWidth / 2 - this.width / 2;
    }
    
    override protected function onClose(event:MouseEvent):void 
    {
        if (queue.length > 0)
        {
            out(queue.shift(), queue.shift());
            
            alertQueue = queue.length / 2;
            
            return;
        }
        
        super.onClose(event);
        
        stageRef.removeChild(this);
        stageRef.removeChild(stageLock);
        stageLock.visible = this.visible = false;
    }
    
    override protected function addChildren():void 
    {
        super.addChildren();
        
        _format = new TextFormat(Style.fontName, Style.fontSize, Style.LABEL_TEXT);
        
        massage = new TextField();
        massage.x = 5;
        massage.y = 5;
        massage.height = _height;
        massage.embedFonts = Style.embedFonts;
        massage.multiline = true;
        massage.wordWrap = true;
        massage.selectable = true;
        massage.defaultTextFormat = _format;    
        _panel.addChild(massage);
        
        stageLock = new Sprite();
        stageLock.visible = false;
        
        ok = new PushButton(_panel, 0, 0, "OK", onClose);
        ok.width = 50;
    }
    
    private static function error(level:int = 0):void
    {
        var nl:String = "\n * "
        var msg:String = "";
        switch(level)
        {
            // Init constractor error
            case 0:
                msg = "This class is not designed" +
                nl + "to be used as a constractor." +
                nl + "Use Alert.out('your massage'); to" +
                nl + "display alert pop up on stage." +
                nl + "Or its also possible to init" +
                nl + "using the out() function if the" +
                nl + "out(msg, title, 'stage') < - stage" +
                nl + "variable is not equal to null";
                break;
                
            // Local instance is null
            case 1:
                msg = "Use Alert.init(stage) before" +
                nl + "using Alert.out() function.";
                break;
                
            // Init function was called more then once
            case 2:
                msg = "Can not use Alert.init()" +
                nl + "function more then 1 times.";
                break;
        }
        
        throw new Error(msg, level);
    }
}