Flint Particle System Forum - Use a class file with ImageClasses to generate particles? Sat, 25 Dec 2010 17:20:02 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher Use a class file with ImageClasses to generate particles? http://flintparticles.org/forum/comments.php?DiscussionID=264&Focus=941#Comment_941 http://flintparticles.org/forum/comments.php?DiscussionID=264&Focus=941#Comment_941 Tue, 20 Oct 2009 20:37:15 +0100 ed
I'm trying to use ImageClasses to "load" an array of MovieClips.


//PHP loaded, XML nodes converted to object properties...

private function dataLoaded(e:DataEvent):void {
_itemArray = e.items;

for (var i:uint = 0; i < _itemArray.length; i++) {
var box:Box = new Box(_itemArray[i].sentence.length);
_boxArray.push(box);
}

images = new ImageClasses(_boxArray);
emitter.counter = new Blast(_boxArray.length);
emitter.addInitializer(images);
emitter.addInitializer(new Position(zone));

renderer.addEmitter(emitter);
renderer.mouseChildren = true;
addChild(renderer);
}

But I keep getting this error:

Error #1034: Type Coercion failed: cannot convert Box@35537451 to Class.

I've compared my code to the snippet seen here: http://flintparticles.org/forum/comments.php?DiscussionID=242&page=1 but I still get the error...any ideas? ]]>
Use a class file with ImageClasses to generate particles? http://flintparticles.org/forum/comments.php?DiscussionID=264&Focus=942#Comment_942 http://flintparticles.org/forum/comments.php?DiscussionID=264&Focus=942#Comment_942 Tue, 20 Oct 2009 22:50:51 +0100 ed Took a hint from this post: http://flintparticles.org/forum/comments.php?DiscussionID=155. I placed the particle first, then added them to the emitter...I'm guessing I could have placed the particles after adding them as well, but this seemed the most straightforward to me.


private function dataLoaded(e:DataEvent):void {
_itemArray = e.items;

for (var i in _itemArray) {
var l:uint = _itemArray[i].sentence.length;
var box:Box = new Box(l);
box.x = 900 * Math.random() + 50;
box.y = 550 * Math.random() + 25;
addChild(box);

box.setData(_itemArray[i]);
_boxArray.push(box);

var particle = Particle2DUtils.createParticle2DFromDisplayObject(box, renderer, emitter.particleFactory);
emitter.addExistingParticles([particle], true);
}

emitter.addInitializer(new Position(zone));

emitter.addAction(new MutualGravity(5, 500, 3));
emitter.addAction(new TurnTowardsMouse(.25, renderer));
emitter.addAction(new BoundingBox(0, 0, 1000, 600));
emitter.addAction(new SpeedLimit(150));
emitter.addAction(new Move());

renderer.addEmitter(emitter);
renderer.mouseChildren = true;
addChild(renderer);

emitter.start();
emitter.runAhead(10);
}


BTW, Richard, thank you for this remarkable system. You've really made particle simulation accessible to everyone. Amazing documentation as well. Hats off to you! ]]>
Use a class file with ImageClasses to generate particles? http://flintparticles.org/forum/comments.php?DiscussionID=264&Focus=950#Comment_950 http://flintparticles.org/forum/comments.php?DiscussionID=264&Focus=950#Comment_950 Mon, 02 Nov 2009 08:01:05 +0000 Richard
I'm pleased you found the solution. It is possible to pass the image directly to the particle -

particle.image = box

but because the emitter works with behaviours, you'd have to wrap this up as an Initializer.

I intend to add a tutorial about writing custom Initializers and Actions soon, but there's a few bits of work I have to get out the way first.

Richard ]]>