Emotioned.com

Ian Cremona

Flash CS4 AS3 Confetti Particle system source files and Class

July16

The SWF

Read more for code and source files

The Class

package com.lynda.particles{
	import flash.display.*;
	import flash.filters.BitmapFilter;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.BlurFilter;
 
	public class Particle extends Sprite {
		public var xVelocity:Number;
		public var yVelocity:Number;
 
		public function Particle() {
			xVelocity=0;
			yVelocity=0;
		}
 
		public function update():void {
			this.x+=xVelocity;
			this.y+=yVelocity;
		}
	}
}

The Movie Actionscript (AS3)

var numOfParticles:uint=10; // For the ribbon
var maxVelocity:Number=8;
var minVelocity:Number=1;
var particles_ary:Array=[];
 
var numOfParticles2:uint=40; // For the short ribbon
var particles2_ary:Array=[];
var maxVelocity2:Number=5;
var minVelocity2:Number=1;
 
var  myColor:ColorTransform = this.transform.colorTransform; //for both
 
function updateStage(event:Event):void {
 
if (particles_ary.length< particles_ary.length; i++) { //set repeat conditions for when particles go off stage var particle:MoveAsset2=particles_ary[i]; var c:ColorTransform = new ColorTransform(); c.color = (Math.random() * 0xFFFFFF); particles_ary[i].update(); if (particle.y>stage.stageHeight+particle.height/2) {
particle.yVelocity = Math.floor(Math.random() * (maxVelocity -  minVelocity)) + minVelocity;
particle.x = Math.floor(Math.random() * ((stage.stageWidth - (particle.width)) -  (particle.width))) + (particle.width);
particle.y=0;
particle.scaleY = particle.scaleX = Math.floor(Math.random() * (3 -  0) + 0);;
 
particle.ribbon_mc.ribbon_mc.color_mc.transform.colorTransform = c;
 
trace("scale = " + particle.scaleX);
if (particle.scaleX||particle.scaleY>1){
particle.alpha = Math.random()* .8 + .2;
}
 
}
}
}
 
addEventListener(Event.ENTER_FRAME, updateStage); // listening
 
function updateStage2(event:Event):void {
 
if (particles2_ary.length< particles2_ary.length; i++) { var particle1:MoveAsset1=particles2_ary[i]; var c:ColorTransform = new ColorTransform(); c.color = (Math.random() * 0xFFFFFF); particles2_ary[i].update(); if (particle1.y>stage.stageHeight+particle1.height/2) {
particle1.yVelocity = Math.floor(Math.random() * (maxVelocity2 -  minVelocity2)) + minVelocity2;
particle1.x = Math.floor(Math.random() * ((stage.stageWidth - (particle1.width)) -  (particle1.width))) + (particle1.width);
particle1.y=0;
particle1.scaleY = particle1.scaleX = Math.floor(Math.random() * (3 -  0) + 0); // change the scale
 
particle1.confetti_mc.color_mc.transform.colorTransform = c;
trace("scale = " + particle1.scaleX);
if (particle1.scaleX||particle1.scaleY>1){
particle1.alpha = Math.random()* .8 + .2; // change the alpha channel according to scale
}
 
}
}
}
 
addEventListener(Event.ENTER_FRAME, updateStage2);

The FLA Source File

Download the FLA source File

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Related posts:

  1. Flash CS4 AS3 XML reader and Tween source code Chilipoker Client Banner,in 7 Languages. Read more for code...

Related posts brought to you by Yet Another Related Posts Plugin.

posted under Design
6 Comments to

“Flash CS4 AS3 Confetti Particle system source files and Class”

  1. Avatar September 7th, 2009 at 3:17 pm Lann Says:

    hi, thank you for the code, i helps me a lot on learning about particles, however i tried to compile the code but it seems that there are few syntax error in the Movie script.

    1. 1084: Syntax error: expecting rightparen before semicolon.
    2. 1084: Syntax error: expecting rightbrace before rightparen.

    both in line 16 which is :

    if (particles_ary.length< particles_ary.length; i++) {

    really appreciate if you could explain a bits about the codes.

    thank you


  2. Avatar September 7th, 2009 at 7:17 pm IanCremona Says:

    Hey Lann, thanks for your comment. I am travelling in Morocco until the end of September – I~ll reply as soon as I get back home


  3. Avatar September 7th, 2009 at 7:25 pm IanCremona Says:

    Hi again Lann,

    try this

    if (var i:int=0; iparticles_ary.length< particles_ary.length; i++) {

    If that does not work leave a comment and Ill get back

    thanks for reading my blog!


  4. Avatar April 13th, 2010 at 9:14 pm kfir miller Says:

    nice forum
    i am a kind of newbe with AS…
    anyway tried to rplace
    if (var i:int=0; iparticles_ary.length< particles_ary.length; i++) {

    got :

    millions of bugs…
    please help.


  5. Avatar April 13th, 2010 at 9:18 pm kfir miller Says:

    could you lease update the file…
    http://emotioned.com/files/Regenerating_Particles.fla

    Thanks.


  6. Avatar July 14th, 2010 at 6:05 pm Aaron Says:

    anyway tried to rplace
    if (var i:int=0; iparticles_ary.length< particles_ary.length; i++) {

    Should DEFINITELY be
    for(var i:int=0; iparticles_ary.length< particles_ary.length; i++) {


Email will not be published

Website example

Your Comment:

Spam Protection by WP-SpamFree

 

What I'm Doing...

Posting tweet...

 

July 2009
M T W T F S S
« Jun   Aug »
 12345
6789101112
13141516171819
20212223242526
2728293031