Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

Thursday, November 8, 2007

AS3 Particle Class release

Thursday, November 8, 2007   

I ported Keith's AS2 Particle Class to AS3. I didn't add anything to it, but I do have plans for extending some areas of it. If you feel that it needs improvement, by all means have at the source and perhaps link to your new class in a comment so we can all share. The class file can be found here.

Hopefully some might find it useful. The class doesn't generate its own art, I have this associated with a symbol in the library at the moment. Also its typed to MovieClip for that reason. You could change it to Sprite (to gain some rendering benefit) and have the class responsible for the graphical display. DL: 70.

Update: (November 2008)
It has become quite clear that my initial quick port didn't come without problems in the source code. I haven't gone back and done anything with it since, so if you're having problems you can resolved those on your own or sometime in the future I will just rewrite the thing so it works correctly.
 
 Return to the main page
Comments:

There are currently 16 Comments:

Anonymous Anonymous said...
“cool, thanks ;) any chance of posting the fla of the example to help explain?”
 
Blogger e.dolecki said...
November 8, 2007 10:48 AM
“You can look here for the original BIT-101 page... look at the documentation. Its the same documentation for use with the AS3 version.”
 
Anonymous Anonymous said...
November 8, 2007 12:11 PM
“Is it possible to post your code?
Or a simple example.”
 
Blogger e.dolecki said...
November 8, 2007 12:53 PM
“A quick test:

Create a mc symbol on stage. Give it an instance (ie. foo_mc). Then in the properties for that mc, in linkage set it like so:

Class: whatever (doesn't matter for this)
Base class: Particle

Make sure the Particle class is in the same dir location as the FLA. If not, use a classpath.

Now on your timeline:

one_mc.wander = 3;
one_mc.setBounds( {xMin:10, yMin:10, yMax:stage.stageHeight - 10, xMax:stage.stageWidth - 10} );

run the SWF & watch your clip move around.

Make sure to use a decent frame rate, like 31.”
 
Blogger Makc said...
November 16, 2007 11:02 AM
“did you tested how many simple clips it can handle without FPS loss?”
 
Blogger Makc said...
November 16, 2007 11:14 AM
“...also, wasnt init call supposed to go into onAddedToStage? since it is in constructor, what is sacred meaning of onAddedToStage?”
 
Blogger Makc said...
November 16, 2007 11:54 AM
“holy crap, man, what did you compiled it with? I have no MouseEvent.PRESS or MouseEvent.RELEASE here, plus stageX and stageY are undefined.”
 
Blogger Makc said...
November 19, 2007 10:41 AM
“hmmm I downloaded it again today, and still same problem, maybe you have wrong file there?”
 
Anonymous Anonymous said...
February 6, 2008 5:58 PM
“That could be. Looks like stageX should be the current x location of the mouse. Perhaps this is flex properties?”
 
Anonymous Anonymous said...
March 26, 2008 8:09 AM
“The file had some errors, but here's how i got it working:

1. I commented away the lines that threw stageX and stageY -errors (that will cause that repelMouse, grawToMouse and springToMouse-functions will not work but I didn't need them so it was ok for me to get rid of them)

2. I changed all of the MouseEvent.PRESS to MouseEvent.MOUSE_DOWN and MouseEvent.RELEASE to MouseEvent.MOUSE_UP

3. Corrected the mistyping of private function pressHander to private function pressHandler

Hope this helps.”
 
Anonymous Anonymous said...
April 18, 2008 6:51 AM
“Hi,

Nice to have this class in AS3, I was working before with this fabulous class in AS2.

Did anyone find how to fix the stageX & stageY errors

thanks in advance ;)”
 
Anonymous Anonymous said...
April 18, 2008 7:19 AM
“I think, I find the solution

parent.mouseX
parent.mouseY

regards ;)”
 
Anonymous Anonymous said...
July 2, 2008 12:17 PM
“Hi everyone ?
Just to say : thank you !
I had an Old experiment with that class in as2,
with about 100 to 200 clips instanced on the stage, using that class !
as soon as i convert the whole thing in as3, i'll tell you about it's Framerate performances in AS3.

regards.”
 
Anonymous benjamin said...
July 2, 2008 5:51 PM
“hello !
I'm quite new in as3 and wanted to use the as3 version of this class i used for this :
http://www.hpilton.com/hpiltonPart.swf.

I created a clip : class : Ball, Base Class: Particle.
and tryed this method to create some particles :

import Particle;

var ball:Ball;
var i:int;
for ( i = 0; i< 50; i++ )
{
ball = new Ball();
addChild ( ball);
//trace( ball.name );
ball.x = Math.random()* 1024;
ball.y = Math.random()* 600;
ball.wander =4;
ball.grav =.3;
}

it return this error :
TypeError: Error #1009:Cannot access a property or method of a null object reference.

What did I do wrong ????”
 
Anonymous benjamin said...
July 2, 2008 5:59 PM
“Hi everyone, not shure my last comment was published, so I do it again !
First thanks 4 this class.
the as2 version was really helpfull.

I'm quite new in as3 and try to update an as2 experiment you can see here :
http://www.hpilton.com/hpiltonPart.swf

I've created an new clip : Class = Ball, Base Class = Particle, and tryed with this code (that soon will stand in another method) to create a few particles instances on the timeline :

import Particle;

var ball:Ball;
var i:int;
for ( i = 0; i< 50; i++ )
{
ball = new Ball();
addChild ( ball);
//trace( ball.name );
ball.x = Math.random()* 1024;
ball.y = Math.random()* 600;
ball.wander =4;
ball.grav =.3;
}

It returns the fallowing error :
TypeError: Error #1009: Cannot access a property or method of a null object reference.

What did I do wrong ???”
 
Anonymous Anonymous said...
November 26, 2008 7:12 AM
“this one sucks. I keep getting about 50 errors saying "undefined propoerty pressHandler" or "undefined proporty RELEASE thorught a reference wihs tatic type calss"”
 
 Leave a comment