3D Particle Effect – Flash CS4 Tutorial

Author : Craig

Author's Website | Articles from

In today's video tutorial, I'll show you how to create an ActionScript 3D particle effect that causes multiple stars to animate out in all directions in 3D space. Here is the ActionScript for this tutorial:

var container:MovieClip = new MovieClip();
addChild(container);
 
root.transform.perspectiveProjection.fieldOfView = 120;
 
addEventListener(Event.ENTER_FRAME, addStar);
 
function addStar(e:Event):void
{
	var mc:star = new star();
	mc.x = stage.stageWidth / 2;
	mc.y = stage.stageHeight / 2;
	mc.z = 0;
	mc.xVel = Math.random() * 4 - 2;
	mc.yVel = Math.random() * 4 - 2;
	mc.zVel = Math.random() * 4 - 2;
	mc.count = 0;
	container.addChild(mc);
	mc.addEventListener(Event.ENTER_FRAME, animate);
}
 
function animate(e:Event):void
{
	e.currentTarget.x += e.currentTarget.xVel;
	e.currentTarget.y += e.currentTarget.yVel;
	e.currentTarget.z += e.currentTarget.zVel;
	e.currentTarget.count++;
	if (e.currentTarget.count >= 100)
	{
		e.currentTarget.removeEventListener(Event.ENTER_FRAME, animate);
		container.removeChild(MovieClip(e.currentTarget));
	}
}

Like this post? Share it!

  • Tweet
  • Facebook
  • Diggit
  • Delicious
  • Diggit
  • Diggit
  • Diggit
  • Diggit
  • Diggit

Related Posts


User Comments


  1. Mearvin
    January 31, 2009

    Awesome tutorial…..It has really helped a lot…thanks a lot…..keep going!!!

    Reply

  2. Flash Designer
    February 22, 2009

    Great tutorial!

    Reply

  3. Jon Mulligan
    March 9, 2009

    It would be great if the stars would topple end over end randomly, that would be awesome!

    Great tutorial.

    Reply

  4. Zenseeker
    March 15, 2009

    Thanks so much for your great tutorials. Just wanted to let you know someone really appreciates them.

    Reply

  5. Rapi
    March 16, 2009

    Wow. Thanks for that great tutorial. Yeah, what zenseeker said. This is too cool. :) Can’t wait to play around with it.

    Reply

  6. Sluff
    April 10, 2009

    Hey, this is a great tutorial man! Thanks a lot :D

    Reply

  7. cretzuuu
    May 6, 2009

    i have a bit of a problem … i get this error back saying this:
    1119: Access of possibly undefined property perspectiveProjection through a reference with static type flash.geom:Transform. ->
    root.transform.perspectiveProjection.fieldOfView = 120;

    Reply

  8. cretzuuu
    May 6, 2009

    sorry for double posting… but i’m in a very big hurry…and i don’t know how to come to a solution… help please

    Reply

  9. Sagir
    May 10, 2009

    Hi Craig,

    Great Job!

    once you maximize the window the center does not propogate to center,

    the instance of star movieclip “mc” changes you might have noticed.

    thank you,

    Sagir

    Reply

  10. J Z
    May 31, 2009

    Great tutorial. You are an awesome teacher.

    Reply

  11. martin
    June 5, 2009

    how can I add text without it being behind the effect.

    Reply

  12. steve
    June 12, 2009

    hello, great tutorial

    however i was inputting the codes and i thought i had it all set right,and i tested it and i only had the single star the in middle of the screen????

    Reply

  13. Andrew
    July 28, 2009

    Thanks for the tutorial!

    However I was wondering how I could incorporate the effect into a tween. I would like to have the effect motion tween over a background layer. Is this possible?

    Thanks,
    -A

    Reply

  14. Joe
    July 29, 2009

    Great tutorial.

    How can I have this play behind other graphics on the stage? I have a logo centered on the stage and what similiar stars behind the logo.

    Reply

  15. Michelle
    November 24, 2009

    awesome job and excellent video explanation

    Reply

  16. Manndy
    November 28, 2009

    Man you just rock. I am really happy to visit your website.
    I know how to do lots of interesting effects in after effects but when it comes down to flash then my knowledge is not so good. But know i think that i can do it in flash also!!! Please post some more tutorials. The best part of this tutorial is that everything is done using as3.

    Reply

  17. Alex
    December 10, 2009

    Excellent tutorial! I have a question about how to unload this when a user hits a replay button. The 3D particle effect stays on screen. What code should I add and where?

    Reply

  18. Karthi
    January 1, 2010

    i’m new to as3 thanks for yur tutorial
    very few lines yet so fabulous understanding thanks a lot

    Reply

  19. lektira
    January 3, 2010

    thx i will use it on my future project

    Reply

  20. corinne
    January 8, 2010

    Thank you very much !

    Reply

  21. Kanishka
    January 31, 2010

    Nice tutorial

    It does not appear in the centre of the window when it’s maximized
    Thanks

    Reply

  22. chico crevin
    February 3, 2010

    Scuse-me I don’t write enghish very well.
    How to put this program without the loop and place not on stage but in a window of 200px by 500px

    Reply

  23. thail long quan
    February 17, 2010

    thanks…

    Reply

  24. Eddy
    February 21, 2010

    Hi,
    great tutorial for a newbie like me :)
    is it also possible to have this on a timer even instead of the enter frame event ? i added a button to start the animation but i can’t figure out how to access the variables outside the function. I would like the animation to start with my button and run for a certain amount of seconds.
    Any push in the right direction would be great :)
    Eddy.

    Reply

  25. Turkis
    March 14, 2010

    Thenks Man

    Reply

  26. Greg
    March 31, 2010

    Excellent tutorial!
    Can’t wait to try it.

    Reply

  27. Luz Elena
    May 18, 2010

    Saludos desde Barcelona, ¡¡¡ Exelentes tutoriales !!!!

    Gracias :)

    Reply

  28. JJ
    June 21, 2010

    Should be like this (for centering)
    mc.y = stage.height / 2;
    mc.y = stage.height / 2;

    Reply

  29. John
    November 13, 2010

    @ manndy…obviously you didnt read the top of the page…this is done in cs4 and not cs3 or as3 as you out it lol

    Great tutorial mate thanks

    Reply

  30. John
    November 13, 2010

    btw once you export the movie and then go fullscreen it stays in the middle

    Reply

  31. Free Online Games
    November 23, 2010

    i have a bit of a problem … i get this error back saying this:
    1119: Access of possibly undefined property perspectiveProjection through a reference with static type flash.geom:Transform. ->
    root.transform.perspectiveProjection.fieldOfView = 120;

    Reply

  32. nailer
    February 7, 2011

    Great job Craig. I’m just starting out and have learned much from watching you. The effect applied to your image in the chair is very intersting. Is there a tutorial for that?

    Reply

  33. elevated
    March 11, 2011

    As always you are helpful as ever with a great tutorial. Can you or will you pass on the “how” of the transition effect you used for the image at the clip start.

    Reply

  34. Tracey
    March 23, 2011

    Thanks so much! I really enjoyed this. I don’t even have cs4 yet, but i can’t wait (now that cs5 is out, oh well). I am just now learning actionscript so it was great to be able to understand what your directives were.

    Reply

  35. EssellGop
    April 29, 2011

    be happy and love. kiss

    Reply

  36. DancingKim
    May 11, 2011

    Howdy, i’m a professional dancer. i’d like to make a showreel to get my promotions. I also prefer to use some animation. Can someone suggest me a good animation studio, but possibly not very expensive? I’m here for 3 months for a tour.
    Love
    Kim.

    Reply

  37. Angielski wrocław
    June 7, 2011

    great tutorial on cool effect. thanks and keep it comming!

    Reply

  38. profeivan
    June 27, 2011

    Great tutorial man. Well explained. Thanks for taking your time to share this with the Flash community. Best regards from Colombia

    Reply

  39. Anonymous
    July 13, 2011

    Another great tutorial! Though, I wonder if it’s possible to fade out the particles before actually removing them.. I’ve experimented different methods, but I haven’t succeeded yet. The reason being my being quite new to actionscript 3.0..

    Reply

  40. Elza Pereira
    December 31, 2011

    Your tutorial is excellent. I am developing my portfolio and I believe in using particles.
    I am Brazilian, I am learning English because I love Flash/AS3.
    Thank you. Big hug.

    Reply

Leave a Reply

 
  Twitter Followers

Stock Flash Files Web Development Tutorials

Stock Graphics Video Files


Your Ad Here