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

test env

developing with this in parallel to test code in an empty template, much faster debug filtering
Get Adobe Flash player
by hemingway 14 Aug 2012
/**
 * Copyright hemingway ( http://wonderfl.net/user/hemingway )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/r3n8
 */

package{
    import com   . bit101   . components.*;
    import fl . transitions . easing.*;
    import fl . transitions . *;
    import flash . net      . *;
    import flash . text     . *; 
    import flash . geom     . *;
    import flash . utils    . *;
    import flash . system   . *;
    import flash . events   . *;  
    import flash . display  . *;
    import flash . filters  . *;
    
    // only define instance of class contextually, cannot instantiate more than one class in a tree
    public class MAIN extends Sprite
    {
        private var _traceLbl : Label;
        
        //0
        public var _sprDrag   : Sprite = new Sprite;
        public var _sprHArea  : Sprite = new Sprite;
        public var _sprTarget : Sprite = new Sprite;
       
        //1
        public var _sprBnds : Sprite = new Sprite;
              
        public var _sprArr  : Array = new Array();
        public var _intArr  : int = 0;
        public var _sprDis  : int;
        public var _sprDx   : int;
        public var _sprDy   : int;
        
        //2
        //public var CF_URL  : URLRequest = new URLRequest("http://www.mediafire.com/conv/889c0bff47421943624a74a8c52f8922d5971b904ad86b615226069adf2a0d036g.jpg");
        public var URL_1   : URLRequest = new URLRequest("http://www.mediafire.com/conv/b2ec7034e5667d587700ea1208cb83c0ef49e4f403ffccb1b2bdc120690ad56f6g.jpg");
        public var URL_2   : URLRequest = new URLRequest("http://www.mediafire.com/conv/996640e124282408e8b65c52cdaf10040f6bc11634b1901b5b54ab2461ac59296g.jpg");        
        
        public var _btnFade : PushButton;
        public var _sleep   : Timer  = new Timer(10000);
        
        public var _sprMask : Sprite = new Sprite;
        public var _sprCont : Sprite = new Sprite;
        public var _sprPix  : Sprite = new Sprite;
        public var _bmpLoad : Loader = new Loader;
        
        public var _ptStart : Point = new Point;
        public var _ptStop  : Point = new Point;
        
        public var _sprBtn : Sprite = new Sprite;
        
        public var _blStart : Boolean = true;
        public var _blBtn   : Boolean = false;
        
        public var _mathIntX : int;
        public var _mathIntY : int;
        
        //3
        public var _sprCube : Sprite = new Sprite;
        
        public function MAIN ():void
        {
          //INIT_Stage(0);
          //INIT_Stage(1);
            INIT_Stage(2);
          //INIT_Stage(3);
        }
        
        public function INIT_Stage (_intStage:int = 0):void
        {
            switch (_intStage)
            {
                case 0:
                
                _sprTarget.graphics.beginFill(0xFF9999);
                _sprTarget.graphics.drawRect(75, 75, 315, 315);
                _sprTarget.graphics.endFill();
            
                _sprHArea.graphics.beginFill(0x333333);
                _sprHArea.graphics.drawRect(135, 135, 125, 125);
                _sprHArea.graphics.endFill();
            
                _sprDrag.graphics.beginFill(0x999999);
                _sprDrag.graphics.drawRect(10, 10, 50, 50);
                _sprDrag.graphics.endFill();
            
                addChild(_sprTarget);
                addChild(_sprHArea);
                addChild(_sprDrag);
            
                addEventListener(MouseEvent.MOUSE_DOWN , EVNT_Action);
                addEventListener(MouseEvent.MOUSE_UP   , EVNT_Action);
                addEventListener(MouseEvent.MOUSE_OVER , EVNT_Action);
                addEventListener(MouseEvent.MOUSE_OUT  , EVNT_Action);
       
                break;
                case 1:
                
                _sprBnds.graphics.beginFill  (0xFFFFFF, 0);
                _sprBnds.graphics.drawCircle (0, 0, 50);
                _sprBnds.graphics.endFill    ();
                
                for (var i:int = 0; i < 50; i++)
                {
                    for (var j:int = 0; j < 50; j++)
                    {
                        _sprArr[_intArr] = new Sprite;
                        _sprArr[_intArr].graphics.beginFill (0x000000);
                        _sprArr[_intArr].graphics.drawRect  (i*10, j*10, 5, 5);
                        _sprArr[_intArr].graphics.endFill   ();
                        
                        addChild(_sprArr[_intArr]);
                        
                        _intArr++;
                    }
                }
                
                addChild(_sprBnds);
                
                addEventListener(Event.ENTER_FRAME, EVNT_Action);
                addEventListener(MouseEvent.MOUSE_MOVE, EVNT_Action);
                
                break;
                case 2:
                _traceLbl = new Label(stage, 25, 1, "G_mX: " + "null" + "; G_mY: " + "null" + "; L_mX: " + "null" + "; L_mY:" + "null" +";"); 

                //_btnFade  = new PushButton(stage, 335, 1, "Swap Image");
                _sprBtn.graphics.lineStyle (1, 0x333333);
                _sprBtn.graphics.beginFill (0x000000, 0.25);
                _sprBtn.graphics.drawRect  (335, 1, 100, 20);
                _sprBtn.graphics.endFill   ();
                _sprBtn.mouseEnabled = false;
                
                _traceLbl = new Label(stage, 357.5, 1, "Swap Image");
                              
                _sprCont.graphics.lineStyle (1, 0x333333);
                _sprCont.graphics.beginFill (0x000000, 0.75);
                _sprCont.graphics.drawRect  (stage.stageWidth * 0.05, stage.stageHeight * 0.05, stage.stageWidth * 0.9, stage.stageHeight * 0.9);
                _sprCont.graphics.endFill   ();
                
                _bmpLoad.load(URL_1);   
                _bmpLoad.x = (stage.stageWidth * 0.05) + 2;
                _bmpLoad.y = (stage.stageHeight * 0.05) + 2;
                _bmpLoad.scaleX = 0.4045;
                _bmpLoad.scaleY = 0.5525; 
                _bmpLoad.mask = _sprCont;
                _bmpLoad.alpha = 0;
                
                _sprMask.graphics.beginFill(0x666666, 1);
                _sprMask.graphics.drawRect (stage.stageWidth * 0.05, stage.stageHeight * 0.05, stage.stageWidth * 0.9, stage.stageHeight * 0.9);
                _sprMask.graphics.endFill  ();     
 
                addChild(_sprCont);
                addChild(_sprBtn);
                addChild(_sprMask);
                
                setTimeout(ACTN_FadeIn, 100);
                
                addEventListener(MouseEvent.MOUSE_DOWN, EVNT_Action);
                addEventListener(MouseEvent.MOUSE_UP  , EVNT_Action);
                break;
                case 3:
                
                _sprCube.graphics.lineStyle  (1, 0x333333);
                _sprCube.graphics.beginFill  (0xFFFFFF);
                _sprCube.graphics.drawCircle (stage.stageWidth/2, stage.stageHeight/2, 50);
                _sprCube.graphics.endFill    ();
                
                addChild(_sprCube);
                
                break;
            }
        }
         
        public function ACTN_FadeOut ():void
        {
            _blBtn =! _blBtn;
            removeChildAt(2);
                            
            if (_blBtn)
            {
                _bmpLoad.load(URL_2);
                        
                _bmpLoad.x = (stage.stageWidth *0.05)+2;
                _bmpLoad.y = (stage.stageHeight *0.05)+2;
                _bmpLoad.scaleX = 0.6775;
                _bmpLoad.scaleY = 0.54;
            }else{
                _bmpLoad.load(URL_1);
                        
                _bmpLoad.x = (stage.stageWidth * 0.05)+2;
                _bmpLoad.y = (stage.stageHeight *0.05)+2;
                _bmpLoad.scaleX = 0.4045;
                _bmpLoad.scaleY = 0.5525;
            }
            
            setTimeout(ACTN_FadeIn, 100); 
        }
        
        public function ACTN_FadeIn ():void
        {
            addChild(_bmpLoad);
            var t:Tween = new Tween(_bmpLoad, "alpha", Strong.easeIn, 0, 1, 1, true);

            _sprBtn.mouseEnabled = true;
        }

        public function EVNT_Action (_E:Event):void
        {
            switch (_E.type)
            {
                case MouseEvent.MOUSE_DOWN:
                //_traceLbl.text = "G_mX: " + mouseX + "; G_mY: " + mouseY + "; L_mX: " + _bmpLoad.mouseX + "; L_mY: " + _bmpLoad.mouseY + ";"; 

                switch (_E.target)
                {
                    case _sprDrag:
                    
                    addEventListener(MouseEvent.MOUSE_MOVE, EVNT_Action);
                    
                    break;
                    case _bmpLoad:

                    //if (_blStart)
                    //{
                        _bmpLoad.width  = stage.stageWidth*3;
                        _bmpLoad.height = stage.stageHeight*3;
                        
                        _ptStart.x = (_bmpLoad.width - _bmpLoad.mouseX);
                        _ptStart.y = (_bmpLoad.height - _bmpLoad.mouseY);  
                        
                        _ptStop.x = (_bmpLoad.width - _bmpLoad.mouseX);
                        _ptStop.y = (_bmpLoad.height - _bmpLoad.mouseY);

                        //_bmpLoad.x -= (_ptStop.x - (_bmpLoad.x - _bmpLoad.mouseX));
                        //_bmpLoad.y -= (_ptStop.y - (_bmpLoad.y - _bmpLoad.mouseY));
                        
                        //_bmpLoad.x -= (_ptStop.x - _ptStart.x);
                        //_bmpLoad.y -= (_ptStop.y - _ptStop.y);
                        
                        //_blStart = false;
                    //}else{
                        //_ptStart.x = (_bmpLoad.width - _bmpLoad.mouseX);
                        //_ptStart.y = (_bmpLoad.height - _bmpLoad.mouseY);  
                    //}

                    addEventListener(MouseEvent.MOUSE_MOVE, EVNT_Action);
                    
                    break;
                    case _sprBtn:
                    
                    _sprBtn.mouseEnabled = false;
                    
                    var t:Tween = new Tween(_bmpLoad, "alpha", Strong.easeOut, 1, 0, 1, true);

                    setTimeout(ACTN_FadeOut, 1000);

                    break;
                }
    
                break;
                case MouseEvent.MOUSE_UP:
                
                removeEventListener(MouseEvent.MOUSE_MOVE, EVNT_Action);
                  
                /*
                _E.target.alpha = 1;
                
                if ((_E.target.x + 50) > 75 && (_E.target.x) < (75 + 315) &&
                    (_E.target.y + 50) > 75 && (_E.target.y) < (75 + 315))
                    {
                        _sprTarget.alpha = 0.6;
                    if ((_E.target.x + 50) > 125 && (_E.target.x) < (125 + 135) &&
                        (_E.target.y + 50) > 125 && (_E.target.y) < (125 + 135))
                    
                        {
                            _sprHArea.alpha = 0.4;
                        }else{
                            _sprHArea.alpha = 1;
                        }      
                    }else{
                        _sprTarget.alpha = 1;
                }
                */

                break;
                case MouseEvent.MOUSE_OVER:
                break;
                case MouseEvent.MOUSE_OUT:
                break;
                case MouseEvent.MOUSE_MOVE:
                
                _ptStop.x = (_bmpLoad.width - _bmpLoad.mouseX);
                _ptStop.y = (_bmpLoad.height - _bmpLoad.mouseY);
                
                _bmpLoad.x -= ((_ptStop.x - _ptStart.x)/2);
                _bmpLoad.y -= ((_ptStop.y - _ptStart.y)/2);

                _sprBnds.x = (mouseX - 00 - 00);
                _sprBnds.y = (mouseY - 00 - 00);

                _sprDrag.x = (mouseX - 10 - 25);
                _sprDrag.y = (mouseY - 10 - 25);
                
                break;
                case Event.ENTER_FRAME:
                _intArr = 0;
                
                for (var i:int = 0; i < 50; i++)
                {
                    for (var j:int = 0; j < 50; j++)
                    {
                        _sprDx = (mouseX - i*10);
                        _sprDy = (mouseY - j*10);

                        _sprDis = Math.sqrt(_sprDx*_sprDx + _sprDy*_sprDy);
                        
                        if (_sprDis < 50)
                        {
                            _sprArr[_intArr].alpha = 0 + (_sprDis/50);
                            
                        }else{
                            _sprArr[_intArr].alpha = 1;
                        }
                        
                        _intArr++;
                    }
                }

                break;
            }
        }
    }
}