Category Archives: Actionscript 2

popcorn classs

import com.greensock.*;
import com.greensock.easing.*;
import flash.filters.*;
import flash.geom.Point;
var center:Point = new Point( 30, 30 );

var longest:Number = Math.sqrt( Stage.width * Stage.width + Stage.height * Stage.height );
var popcornElements:Array = [];
var popcornClasses:Array = [ 'PC1', 'PC2'/*, 'PC3'*/, 'PC4', 'PC5', 'PC6', 'PC7', 'PC8' ];

var xSpace:Number = 19;
var ySpace:Number = 19;

var xVar:Number = 3;
var yVar:Number = 3;

var xPos:Number = 0;
var yPos:Number = 0;

var pc:MovieClip;
var amount:Number = popcornClasses.length;
var done:Boolean = false;

var delayCurrent:Number = 3;
var delayMin:Number = 0;
var delayStep:Number = delayCurrent / ( Stage.height / ySpace );

var inTweens:Array = [];
var outTweens:Array = [];
var smallestDistance:Number = 10000;
while(!done)
{
pc = MovieClip( attachMovie( popcornClasses[ AlmostRandom.getRandomInt( 0, amount - 1 ) ], 'p_' + popcornElements.length, getNextHighestDepth() ) );
pc.origX = pc._x = xPos + AlmostRandom.getRandomRange( -xVar, xVar );
pc.origY = pc._y = yPos + AlmostRandom.getRandomRange( -yVar, yVar );
pc._rotation = AlmostRandom.getRandomRange( 0, 360 );

pc.filters = [ new DropShadowFilter( 2, 45, 0x0, 1, 4, 4, 0.4 ) ];

xPos += xSpace;

if ( xPos > Stage.width )
{
xPos = 0;
yPos += ySpace;
delayCurrent -= delayStep;
}

if ( yPos > Stage.height + 10 )
{
done = true;
}

popcornElements.push( pc );
pc.distanceToCenter = Point.distance( center, new Point( pc._x, pc._y ) );
pc.distancePercentage = pc.distanceToCenter / longest;
pc.distancePercentageInverted = 1 - pc.distancePercentage;

inTweens.push( TweenLite.from( pc, 1, { _y:-Stage.height*2 , _rotation:AlmostRandom.getRandomRange( -360, 360 ),ease:Sine.easeIn, delay:delayCurrent + AlmostRandom.getRandomRange( 0, .5 ) } ) );
}

popcornElements.sort( function( p1:MovieClip, p2:MovieClip ):Number {
return p1.distanceToCenter - p2.distanceToCenter;
} );

var i:Number = 0;
var len:Number = popcornElements.length;
var outPos:Point;
var outPosClone:Point;

for ( ;i < len; i++ )
{
pc = popcornElements[i];
outPos = new Point( pc.origX - center.x, pc.origY - center.y );
outPos.normalize(longest + 50);

outTweens.push(
TweenLite.to( pc, 1.5, {
_x:center.x + outPos.x,
_y:center.y + outPos.y,
_xscale:100,
_yscale:100,
ease:Cubic.easeIn
} )
);
}

var inAnimation:TimelineLite = new TimelineLite( { tweens:inTweens, onComplete:Delegate.create( this, prepStage ) } );
var outAnimation:TimelineLite = new TimelineLite( { tweens:outTweens } );

var inAnimTime:Number = 3;
var outAnimTime:Number = 2;

inAnimation.timeScale = inAnimation.totalDuration / inAnimTime;
outAnimation.timeScale = outAnimation.totalDuration / outAnimTime;

var animation:TimelineLite = new TimelineLite( { tweens:[
inAnimation,
TweenLite.delayedCall(1, _parent.reveal.playBanner),
outAnimation

], align:TweenAlign.SEQUENCE, onComplete:Delegate.create( this, cleanUp ) } );
function prepStage():Void
{
//._visible = false;
TweenLite.to( _parent.intro, 0.5, { _alpha:0, ease:Sine.easeIn });
_parent.reveal._alpha = 100;
}
function cleanUp():Void
{
this.removeMovieClip();

for ( var i:Number = 0, len:Number = popcornElements.length;i < len; i++ )
{
TweenLite.killTweensOf( pc );
pc = popcornElements[i];
pc.removeMovieClip();
}
}