Flash CS4 AS3 Confetti Particle system source files and Class
July
16
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
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
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
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
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!
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.
could you lease update the file…
http://emotioned.com/files/Regenerating_Particles.fla
Thanks.
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++) {