Learning AS3, Particle Stuff Help
Copy link to clipboard
Copied
I'm basically trying to make a bunch of particles jump around. I've used the draw tools to draw a small red puff. When you click the puff shoots up from the cursor a few pixels before falling down.
I need help understanding how to call the information from this .as file in another file. This way I will take out the click functionality from the file I have done and have the puffs shoot out automatically at the mouseX and mouseY coordinates.
I eventually want to have these puffs shoot out from a character as it runs across the screen in a game I have planned. It will make it much easier to have these puffs called from a seperate file I believe.
Any help will be greatly appriciated. Here is the code I have so far:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class particle extends MovieClip {
private var mcParticle:MovieClip = new MovieClip();
private var particleArray:Array = new Array();
public function particle() {
stage.addEventListener(MouseEvent.CLICK, drawParticle);
}
public function drawParticle(event:MouseEvent) {
mcParticle.xMovement=Math.random()*20-10;
mcParticle.yMovement=Math.random()*10-10;
//
mcParticle.graphics.beginFill(0xFF0000, .2);
mcParticle.graphics.drawCircle(mouseX,mouseY,5);
mcParticle.graphics.beginFill(0xFF0000, .4);
mcParticle.graphics.drawCircle(mouseX,mouseY,4);
mcParticle.graphics.beginFill(0xFF0000, .6);
mcParticle.graphics.drawCircle(mouseX,mouseY,3);
mcParticle.graphics.beginFill(0xFF0000, .8);
mcParticle.graphics.drawCircle(mouseX,mouseY,2);
mcParticle.graphics.beginFill(0xFF0000, 1);
mcParticle.graphics.drawCircle(mouseX,mouseY,1);
particleArray.push(mcParticle);
this.addChild(mcParticle);
mcParticle.cacheAsBitmap=true;
addEventListener(Event.ENTER_FRAME, animateParticle);
}
public function animateParticle(e:Event) {
mcParticle.x+=mcParticle.xMovement;
mcParticle.y+=mcParticle.yMovement;
mcParticle.yMovement += .5;
}
}
}
Thanks again
Calvin Tennant
Copy link to clipboard
Copied
instead of drawing those circles at mouseX,mouseY draw them where you want them. and intead of calling drawParticle() on a click event, call it when you want.
Copy link to clipboard
Copied
It just so happens that I want them at mouseX and mouseY.. and I wanted to call drawParticle on a click event. I don't understand your post at all. I want to know how to call the information from a .as file in another .as file.
Copy link to clipboard
Copied
ok.
Copy link to clipboard
Copied
Thanks for the help..
Anyone have any clue if this is possible?
Copy link to clipboard
Copied
you're welcome.
your post makes no sense except in light of your 3rd paragraph in your first message. and in that situation you could create a player class that has access to the stage, imports the particle class, creates a particle instance whenever you want your player to create a puff, adds the puff to the display list and assigns the particle's x,y - presumably related to the players x,y.
Copy link to clipboard
Copied
"presumably related to the players x,y."
Absolutly, except I dont have a player yet, so I wanted to demonstrate the ability to do this by snaping it to the mouseX and mouseY
"imports the particle class"
How does one go about doing this?
Thank you for the help, I really appriciate it.
Copy link to clipboard
Copied
you can import any class by using:
import anyclass;
for the particle class:
import particle;
case counts so if your class if Particle - and i can't remember if it is or isn't - you should use:
import Particle;
as long as the particle class is in the same class path as the importing class. (in this situation that probably means the 2 class files are in the same directory.)

