illusion_01

by greentec
♥0 | Line 54 | Modified 2014-05-28 15:48:55 | MIT License
play

ActionScript3 source code

/**
 * Copyright greentec ( http://wonderfl.net/user/greentec )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jJlI
 */

package {
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    import com.bit101.components.Slider;
    public class FlashTest extends Sprite {
        
        public var yRect:Sprite;
        public var ySpeed:int = 2;
        public var direction:int = 1;
        public var slider:Slider;
        
        public function FlashTest() {
            // write as3 code here..
            var g:Graphics = this.graphics;
            
            
            for(var i:int=0;i<20;i+=1)
            {
                if(i%2==0)
                {
                    g.beginFill(0x0);
                    
                }
                else
                {
                    g.beginFill(0xffffff);
                }
                
                g.drawRect(i*465/20,0,465/20,465);
                g.endFill();

            }
            
            yRect=new Sprite();
            yRect.graphics.beginFill(0xffff00);
            yRect.graphics.drawRect(0,465/2-100,40,40);
            yRect.graphics.endFill();
            
            yRect.graphics.beginFill(0x0000ff);
            yRect.graphics.drawRect(0,465/2+100,40,40);
            yRect.graphics.endFill();
            
            addChild(yRect);
            
            slider = new Slider(Slider.HORIZONTAL, this, 10, 465-25, onChange);
            slider.setSize(150, 15);
            slider.value=ySpeed;
            slider.maximum=20;
            slider.minimum=0;
            
            addEventListener(Event.ENTER_FRAME, onLoop);
        }
        
        public function onChange(e:Event):void
        {
            ySpeed=slider.value;
        }

        
        public function onLoop(e:Event):void
        {
            yRect.x += ySpeed * direction;
            if(yRect.x>465-40 || yRect.x<0)
            {
                direction *= -1
            }

        }

    }
}