Hey, Wezlou,
Welcome to actionscript programming! The bullet doesn't move because the command that you think is going to make the bullet move only happens once:
In order for this command to happen more than once, on a continuous basis, you have to put it into an event that fires continually. ENTER_FRAME is one choice, a Timer event is another. Learn the ENTER_FRAME technique first, though, because it's easiest:
ActionScript Code:
stage.addEventListener(MouseEvent.MOUSE_DOWN, shoot);
function shoot(e:Event):void {
var Bullet:bullet = new bullet();
Bullet.x = mouseX;
Bullet.y = mouseY;
addChild(Bullet);
Bullet.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
function enterFrameHandler(event:Event) {
event.target.y = event.target.y - 5;
}
Notice that inside the enter frame event handler function, the name "Bullet" is not used, instead "event.target" is used. Why? Well, you can't use the name "Bullet" anymore, because that variable was created inside another function, and outside of that function the name "Bullet" is not known anymore. The variable name has gone "out of scope." However, "event.target" can be extremely handy, because it lets you re-use the same listener function. Inside the function, "event.target" is like saying "whatever object was given this handler as a listener." So it makes it more anonymous. In fact, if you keep clicking, you keep getting another bullet, and each succeeding one gets this same handler assigned to it.
There is now another problem though. Each bullet simply keeps going, up and up and up, right off the screen. And, for all you know, it's still going up into negative y locations as long as your program keeps running. This consumes memory unnecessarily, and to avoid it you might do something like this:
ActionScript Code:
stage.addEventListener(MouseEvent.MOUSE_DOWN, shoot);
function shoot(e:Event):void {
var Bullet:bullet = new bullet();
Bullet.x = mouseX;
Bullet.y = mouseY;
addChild(Bullet);
Bullet.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
function enterFrameHandler(event:Event) {
event.target.y = event.target.y - 5;
if(event.target.y < 20) {
event.target.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
removeChild(MovieClip(event.target));
}
}
In the above, I set the determinant y location at "< 20" so that you can watch it disappear. First the enter frame event listener is removed from it, then it is removed from the display list.