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

GUI_Constructor

simple methods based on user interaction which construct UI objects for use in AS3
Get Adobe Flash player
by hemingway 23 Jul 2012
    Embed
/**
 * Copyright hemingway ( http://wonderfl.net/user/hemingway )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/phTV
 */

/* ---------------------- *
 *    GUI_Constructor     *
 *  "Efficiency applet"   *
 *    Walker Dalton       *
 * ---------------------- */

package {
    import flash.display.AVM1Movie;
    import com   . bit101  . components.*;
    import flash . display . *;
    import flash . events  . *;
    import flash . geom    . *;

    public class GUI_Constructor extends Sprite {
        /////////////////////////////
        // OBJECTS (by instance)
        /////////////////////////////
        //rect controls
        var bitBtnRect : PushButton;
        var bitSlXRect : VUISlider;
        var bitSlYRect : VUISlider;
        var bitSlWRect : VUISlider;
        var bitSlHRect : VUISlider;  
        var bitRefRect : Text;
        var bitColRect : Text;
        var bitLCRect  : Text;
        var bitLTRect  : Text;
        //circ controls
        var bitBtnCirc : PushButton;
        var bitSlXCirc : VUISlider;
        var bitSlYCirc : VUISlider;
        var bitSlWCirc : VUISlider;
        var bitSlHCirc : VUISlider;
        var bitRefCirc : Text;
        var bitColCirc : Text;
        var bitLCCirc  : Text;
        var bitLTCirc  : Text;
        //???
        var bitLblEvnt : Label;
        //draw panel
        var bitPnlDraw : Panel;
        var bitChkRect : CheckBox;
        var bitChkCirc : CheckBox;
        /////////////////////////////
        // GLOBALS (by instance)
        /////////////////////////////
        //children manipulation
        var _chCount : int = -1;
        var _cachePt : Point = new Point;
        //draw panel
        var shpArray : Array = new Array;
        var _shpCount: int = 0;
        
        public function GUI_Constructor() : void{
            
            bitRefRect = new Text      (stage, 5, 5  , "Reference");
            bitColRect = new Text      (stage, 5, 30 , "0x000000");
            bitSlXRect = new VUISlider (stage, 5, 50 , "X"       ,_eSlider);
            bitSlYRect = new VUISlider (stage, 32, 50, "Y"       ,_eSlider);
            bitSlWRect = new VUISlider (stage, 59, 50, "W"       ,_eSlider);
            bitSlHRect = new VUISlider (stage, 86, 50, "H"       ,_eSlider);
            bitLCRect  = new Text      (stage, 5, 195, "0xFFFFFF");
            bitLTRect  = new Text      (stage, 5, 220, "Thickness");
            
            bitLblEvnt = new Label     (stage, (stage.stageWidth*0.94), (stage.stageHeight*0.47), "");
            bitPnlDraw = new Panel     (stage, 5, 250);
            
            bitChkRect = new CheckBox  (stage, 320, 235, "Rectangle", function(e:Event):void{_eChkbox(bitChkCirc, e)});
            bitChkCirc = new CheckBox  (stage, 390, 235, "Circle"   , function(e:Event):void{_eChkbox(bitChkRect, e)});
            
            bitLTRect.width   = bitLCRect.width  = bitColRect.width  = bitRefRect.width  = 100;
            bitLTRect.height  = bitLCRect.height = bitColRect.height = bitRefRect.height = 20;
            bitSlYRect.height = bitSlHRect.height= 130;
            bitPnlDraw.width  = (stage.stageWidth*0.98);
            bitPnlDraw.height = (stage.stageHeight*0.45);
            
            bitSlXRect.maximum = bitPnlDraw.width;
            bitSlYRect.maximum = bitPnlDraw.height;
            bitSlWRect.maximum = bitPnlDraw.width;
            bitSlHRect.maximum = bitPnlDraw.height;
            
            bitPnlDraw.addEventListener(MouseEvent.MOUSE_DOWN , _ePanel);
            bitPnlDraw.addEventListener(MouseEvent.MOUSE_UP   , _ePanel);
        }
        
        public function _getChildren(objRef:Object, boolPt:Boolean) : int{
            //add support for overlap objects
            _chCount = -1;
            
            if (boolPt == true){
                for (var i : int = 0; i == stage.numChildren; i++){
                    if (objRef.getChildAt(i).hitTestPoint(mouseX, mouseY) == true){
                            _chCount = (i);
                    }
                }
            }else{
                for (var i : int = 0; i == stage.numChildren; i++){
                    if (objRef.hitTestObject(objRef.getChild(i))){
                        _chCount = (i);
                    }
                }              
            }
            return _chCount;
        }
        
        /////////////////////////////
        // EVENTS
        /////////////////////////////
        
        public function _eChkbox(objRef:Object, e:Event) : void{
           //deprecate the verbose event function calls @ definition with a for-loop or swap to using radio buttons
           e.target.selected =! (e.target.selected =! e.target.selected);
           objRef.selected = false;
        }

        public function _eSlider(e:Event) : void{
            //?
        }
        
        public function _ePanel(e:Event) : void{
           var _currPt  : Point = new Point;
            
            switch (e.type){
                case "mouseDown":
                _chCount = _getChildren(bitPnlDraw, true);

                if (_chCount > -1){
                    bitPnlDraw.addEventListener(MouseEvent.MOUSE_MOVE, _ePanel);
                    bitPnlDraw.addEventListener(MouseEvent.MOUSE_UP   , _ePanel);
                }else{
                    if (bitChkRect.selected == true){
                        
                        for (var i:int = _shpCount; i<_shpCount+1; i++){
                            shpArray[i] = new Shape;
                            bitPnlDraw.addChild(shpArray[i]);
                            _shpCount++;
                        }
                        
                        //shpRect.graphics.beginFill(0xC2C2C2);
                        //_cachePt.x = mouseX - bitPnlDraw.x;
                        //_cachePt.y = mouseY - bitPnlDraw.y;
                        //shpRect.graphics.drawRect(_cachePt.x, _cachePt.y, 4, 4);
                        //shpRect.graphics.endFill();

                        bitPnlDraw.addEventListener(MouseEvent.MOUSE_MOVE, _ePanel);
                    }else if (bitChkCirc.selected == true){
                        //draw new circ
                    }else{
                        //draw pt
                    }
                }
                break;
                case "mouseUp":
                    bitPnlDraw.removeEventListener(MouseEvent.MOUSE_MOVE, _ePanel);
                    _cachePt.y = _cachePt.x = 0;
                break;
                case "mouseMove":
                    if (_chCount < 0){
                        _currPt.x = mouseX - bitPnlDraw.x;
                        _currPt.y = mouseY - bitPnlDraw.y;

                        shpArray[_shpCount-1].width  = mouseX - bitPnlDraw.x - shpArray[_shpCount-1].x;
                        shpArray[_shpCount-1].height = mouseY - bitPnlDraw.y - shpArray[_shpCount-1].y;

                        bitLblEvnt.text = _currPt.x + "\n" + _currPt.y;
                    }
                break;
            }
        }
        
        /*
        public function _defineName() : void{
            
            bitBtnRect.name  = "Button";
            bitSlXRect.name  = "Slider";
            bitSlYRect.name  = "Slider";
            bitSlWRect.name  = "Slider";
            bitSlHRect.name  = "Slider";
            bitRectXLbl.name = "Label";
            bitRectYLbl.name = "Label";
            bitRectWLbl.name = "Label";
            bitRectHLbl.name = "Label";
            bitRefRect.name  = "Text";
            bitColRect.name  = "Text";
            bitLCRect.name   = "Text";
            bitLTRect.name   = "Text";
            
            bitBtnCirc.name  = "Button";
            bitSlXCirc.name  = "Slider";
            bitSlYCirc.name  = "Slider";
            bitSlWCirc.name  = "Slider";
            bitSlHCirc.name  = "Slider";
            bitCircXLbl.name = "Label";
            bitCircYLbl.name = "Label";
            bitCircWLbl.name = "Label";
            bitCircHLbl.name = "Label";
            bitRefCirc.name  = "Text";
            bitColCirc.name  = "Text";
            bitLCRect.name   = "Text";
            bitLTRect.name   = "Text";
            
            bitEvntLbl.name  = "Label";
        }
        */       
    }
}