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));
}
}
Tags: 3D, ActionScript, Flash, particle effect, tutorial
Awesome tutorial…..It has really helped a lot…thanks a lot…..keep going!!!
Great tutorial!
It would be great if the stars would topple end over end randomly, that would be awesome!
Great tutorial.
Thanks so much for your great tutorials. Just wanted to let you know someone really appreciates them.
Wow. Thanks for that great tutorial. Yeah, what zenseeker said. This is too cool.
Can’t wait to play around with it.
Hey, this is a great tutorial man! Thanks a lot
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;
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
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
Great tutorial. You are an awesome teacher.
how can I add text without it being behind the effect.
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????
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
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.
awesome job and excellent video explanation
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.
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?
i’m new to as3 thanks for yur tutorial
very few lines yet so fabulous understanding thanks a lot
thx i will use it on my future project
Thank you very much !
Nice tutorial
It does not appear in the centre of the window when it’s maximized
Thanks
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
thanks…
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.
Thenks Man
Excellent tutorial!
Can’t wait to try it.
Saludos desde Barcelona, ¡¡¡ Exelentes tutoriales !!!!
Gracias
Should be like this (for centering)
mc.y = stage.height / 2;
mc.y = stage.height / 2;
@ 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
btw once you export the movie and then go fullscreen it stays in the middle
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;
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?
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.
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.
be happy and love. kiss
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.
great tutorial on cool effect. thanks and keep it comming!
Great tutorial man. Well explained. Thanks for taking your time to share this with the Flash community. Best regards from Colombia
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..
[...] http://www.schoolofflash.com/2008/12/3d-particle-effect-flash-cs4-tutorial/ [...]
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.
Thank you so much good sir. It’s nice to find an advanced tutorial like this that actually works. Good AC3 is hard to find. The explanation that flows through the tutorial is also very intuitive and descriptive.
I just wanted to thank you for this tutorial. !t was so helpful! I look forward to watching others.
can you please post a tutorial regarding the effects you create in making your picture in the start of the video..thanks(^^,)