flash on 2011-9-23

by bradsedito
♥0 | Line 64 | Modified 2011-09-23 07:28:09 | MIT License
play

ActionScript3 source code

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

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.ui.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    
    
    public class ParallaxAS3 extends Sprite
    {
        public var SW    :Number = new Number( stage.stageWidth );
        public var SH    :Number = new Number( stage.stageHeight);
        public var DEPTH :Number = new Number( 5000 );
    
        public function ParallaxAS3()
        {
            var horizon:Sprite;
            var box1:Sprite;
            var box2:Sprite;
            var box3:Sprite;
            var box4:Sprite;
            var box5:Sprite;
            var VP:Sprite;// = new uint(    {x:(stage.stageWidth / 2), y:((stage.stageWidth+80) / 2), z:0}    );
            var POV = {x:0,y:0,z:0,fl:200};
            var boxArray = [box1,box2,box3,box4,box5];
            
            addChild( horizon );

            VP.x = SW/2;
            VP.y = (SW+80)/2;
            VP.z = 0;
            horizon.y = VP.y;
            
            trace(POV.x, POV.x, POV.fl);
            
        function setClips()
            {
                for (var i=0; i<boxArray.length; i++) {
                    setInit(boxArray[i], i*10);
                    //boxArray.x = Math.random() * 50;
                }
            }
            
        function setInit(mc:MovieClip, newZ:Number=0)
        {
            mc.zPos = mc.zStartPos = newZ;//set postiion
            mc.xOff = mc.x - VP.x;//capture offsets
            mc.yOff = mc.y - VP.y;
            mc.zOff = mc.zPos - VP.z;
        }
            
        function positionElements()
        {
            for (var i=0; i<boxArray.length; i++) 
            {
                positionElement(boxArray[i]);
            }
        }   
            
        function positionElement(mc:MovieClip)
        {
            mc.zPos = mc.zStartPos + POV.z;
            var scale = POV.fl/(POV.fl+mc.zPos);
            mc.scaleX = mc.scaleY = scale;
            mc.x = VP.x + (POV.x * scale) - mc.xOff * scale;
            mc.y = VP.y + (POV.y * scale) - mc.yOff * scale;
        }
            
        setClips();
           
        TweenMax.to(POV, 1, {x:"-300", z:"0", ease:Strong.easeInOut, delay:0, onUpdate:positionElements});
        TweenMax.to(POV, 1, {x:"800", z:"200", ease:Strong.easeInOut, delay:1, onUpdate:positionElements});
        TweenMax.to(POV, 1, {x:"-400", z:"400", ease:Strong.easeInOut, delay:2, onUpdate:positionElements});
     
        }
    }
}