Now, sure, we can make a fireball that is perfectly round so you can shoot it in any direction with the same code. But, since you've already gathered all this info about which way your character is facing... why can't you use the same code to make it fire in different directions? Well of course you can.
Set up the fireball MC similar to the character MC, one frame of initializations with nothing but code in it, and four frames labeled "up", "down", "left", "right", and if applicable, some kind of "destroy" frame in the event of a hit. This way, the dir variable you already have can be ported directly to the fireball. Now here's the code you put in frame one:
moveSpeed = 15; //or whatever speed you want
dir = _parent.dir; //retrieve variables from character clip
horiz = _parent.horiz;
vert = _parent.vert;
lifeSpan = 50; //fireball life span, in frames
age = 0; //fireballs life span counter
//defining functions makes for easily alterable and legible code
function fireBallMove(){
age++;
hitCheck();
if (age > lifeSpan){
this.onEnterFrame = null;
gotoAndPlay("destroy");
}
this._x += moveSpeed * horiz;
this._y += moveSpeed * vert;
}
function hitCheck(){
//hitTest code here, i'll just make something up
if (this.hitTest(enemy)){
enemy.gotoAndPlay("takeDamage");
this.onEnterFrame = null;
gotoAndPlay("destroy");
}
}
this.onEnterFrame = fireBallMove();
gotoAndStop(dir);
The "destroy" frame will be the first frame of an animation sequence that will remove the fireball from the screen. On the last frame of this sequence, there should be this action:
this.removeMovieClip();
Now, to make this fireball come into play, you have to attach it to the screen... somehow... Start out by Exporting the fireball MC:
Right click on the fireball in the Library Panel, select 'Linkage', and check 'Export for actionscript' (and 'Export in first frame'). Give it an identifier name like "fireBall". Now, stick this code in the Character MC, in both the 'idle' and 'walk' functions:
if (Key.isDown(Key.SPACE)){
layer++; //important! reusing layers will destroy other clips
this.attachMovieClip("fireBall", "fireBall" + layer, layer);
layer++; //maybe i'm a little OC, but i always increment layers twice
}
That'll attach the clip to the movie. Since all the scripts the fireball needs to move and work are in the fireball clip, you don't have to worry about doing anything else to it.