Can't make MovieClip in function dissapear - function

I'm trying to make simple shooting game with Fiat Multipla falling up to bottom of the screen. I have created function to generate falling multipla and within this function I have a problem.
The main issue is that after change of multideath status to 1 "Death" function does nothing even if It is kept with ENTER_FRAME. Child becomes invisible as I implemented it in multipla movieclip, but even after response from there with Death = 1, nothing happens.
I'm new to all this, I've met and solved few issues during programming, but here's my brickwall for now. Code's either failing completely or I don't know something that's obvious. As I said, I'm newbie.
Thanks a lot for help!
Here's the function:
import flash.events.Event;
import flash.desktop.NativeApplication;
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
Mouse.hide();
var velocity = 0;
var ammo = 6;
LGUI.LGUIammo.gotoAndStop(6);
var counter = 0;
function multiplarain()
{
var x1 = Math.ceil(Math.random() * 280);
var y1 = -200;
var random:Multipla = new Multipla();
var life = 265;
var multideath = 0;
random.x = 100 + x1;
random.y = y1
addChild(random);
random.gotoAndStop(1);
setChildIndex(random, +1);
addEventListener(Event.ENTER_FRAME, Death);
function Death(event:Event):void
{
if(multideath >= 1)
{
removeEventListener(Event.ENTER_FRAME, Death);
removeChild(random);
}
}
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
function fl_EnterFrameHandler(event:Event):void
{
if(random.y >= 680)
{
removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler)
removeChild(random);
trace("rofl");
}
}
random.addEventListener(Event.ENTER_FRAME, fl_AnimateVertically);
function fl_AnimateVertically(event:Event)
{
velocity = velocity + 0.000035;
random.y += 1.5 + velocity;
}
random.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler);
function fl_TapHandler(event:TouchEvent):void
{
counter = counter + 1;
ammo -= 1;
}
if(ammo == 6)
{
LGUI.LGUIammo.gotoAndStop(6);
}
if(ammo == 5)
{
LGUI.LGUIammo.gotoAndStop(5);
}
if(ammo == 4)
{
LGUI.LGUIammo.gotoAndStop(4);
}
if(ammo == 3)
{
LGUI.LGUIammo.gotoAndStop(3);
}
if(ammo == 2)
{
LGUI.LGUIammo.gotoAndStop(2);
}
if(ammo == 1)
{
LGUI.LGUIammo.gotoAndStop(1);
}
if(ammo <= 0)
{
LGUI.LGUIammo.gotoAndStop(7);
}
HGUI.saved.text = counter;
this.addEventListener( Event.ENTER_FRAME, handleCollision)
var kucyk = LGUI.LGUIlife.lifeitself;
function handleCollision(e:Event):void
{
if (random.hitTestObject(LGUI))
{
kucyk = LGUI.LGUIlife.lifeitself;
kucyk.width -= 0.1;
}
/*if (kucyk.width == 0.75)
{
trace("cycki");
NativeApplication.nativeApplication.exit();
}*/
}
}
and here's multipla's movieclip in library code:
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
this.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler2);
function fl_TapHandler2(event:TouchEvent):void
{
this.gotoAndPlay(2);
}
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
function fl_EnterFrameHandler(event:Event):void
{
if(this.currentFrame == 60)
{
this.visible = false;
MovieClip(root).multideath = 1;
trace(MovieClip(root).multideath);
removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
removeEventListener(Event.ENTER_FRAME, fl_TapHandler2);
}
}

it's been like 10 years since I last time worked with AS2 but I'd guess that this Multipla sets the multideath property in the wrong place. If i remember corrctly, root is the top-most level (your application). So if your first code is not on the main timeline but in a movieclip that is on the main timeline it won't work. Try to put a trace into the Death function to see if the multideath is really changing there:
trace(multideath);
try this in the multipla code:
parent.multideath = 1;
instead of
MovieClip(root).multideath = 1;
And I'm asking myself why do you need so many enter frame listeners? You can have just one and combine all animations in one function.
Also you don't need to check for multideath on every frame, just remove the movieclip in a separate function:
function removeMultipla():void
{
removeChild(random);
}
Just call this function from your Multipla instead of setting the multideath property:
parent.removeMultipla();

Related

"TypeError: Error #1009: Cannot access a property or method of a null object reference" while using gotoAndplay function

I was trying to add a gameover screen with a restart button for my game.I had placed the restart button at frame 22.When my player dies it goes to frame 22 and i'm able to restart the game on clicking the button,but this message gets looped in the output area.Please help me how i can correct this issue.
Issue is not there when i remove the line
gotoAndPlay(22);
at Frame 17,but without that i will not get the desired functionality.
Please find my code below
At Frame 17 - Game code
stop();
import flash.events.Event;
import flash.events.MouseEvent;
var mouseIsDown = false;
var speed = 0;
var score = 0;
addEventListener(Event.ENTER_FRAME,mainLoop);
stage.addEventListener(MouseEvent.MOUSE_DOWN,clicked);
stage.addEventListener(MouseEvent.MOUSE_UP,unclicked);
function clicked(m:MouseEvent)
{
mouseIsDown = true;
}
function unclicked(m:MouseEvent)
{
mouseIsDown = false;
}
function mainLoop(e:Event)
{
score = score + 10;
output.text = "Score: "+score;
if(mouseIsDown)
{
speed -= 2;
}
else
{
speed+=2;
}
if(speed > 10) speed = 10;
if(speed < -10) speed = -10;
player.y += speed;
for(var i = 0; i < numChildren; i++)
{
if (getChildAt(i) is Cloud || getChildAt(i) is Boundary)
{
var b = getChildAt(i) as MovieClip;
if(b.hitTestObject(player))
{
for(var counter = 0; counter < 12; counter++)
{
var boom = new Boom();
boom.x = player.x;
boom.y = player.y;
boom.rotation = Math.random() * 360;
boom.scaleX = boom.scaleY = 0.5 + Math.random();
addChild(boom);
}
player.visible = false;
removeEventListener(Event.ENTER_FRAME,mainLoop);
gotoAndPlay(22);
}
}
}
}
At frame 22 - Restart screen
stop();
import flash.events.MouseEvent;
foutput.text = "Score: "+ fscore;
btn_playagain.addEventListener(MouseEvent.CLICK, playagain);
function playagain(m:MouseEvent)
{
gotoAndPlay(17);
}
btnback3.addEventListener(MouseEvent.CLICK, backMain3);
function backMain3(m:MouseEvent)
{
gotoAndPlay(1);
}
At frame 1 - Main Menu screen
stop();
import flash.events.MouseEvent;
import flash.system.fscommand;
btnnewgame.addEventListener(MouseEvent.CLICK, newGame);
function newGame(m:MouseEvent)
{
gotoAndPlay(17);
}
btnins.addEventListener(MouseEvent.CLICK, instruct);
function instruct(m:MouseEvent)
{
gotoAndPlay(6);
}
btncredits.addEventListener(MouseEvent.CLICK, credits);
function credits(m:MouseEvent)
{
gotoAndPlay(11);
}
btnexit.addEventListener(MouseEvent.CLICK, exitfunc);
function exitfunc(m:MouseEvent)
{
fscommand("quit");
}
At Frame 6 - Instructions Screen
stop();
btnback1.addEventListener(MouseEvent.CLICK, backMain1);
function backMain1(m:MouseEvent)
{
gotoAndPlay(1);
}
At Frame 11 - Credits Screen
stop();
btnback2.addEventListener(MouseEvent.CLICK, backMain2);
function backMain2(m:MouseEvent)
{
gotoAndPlay(1);
}
That error means that you are trying to call a method on a null object, meaning one of the objects you are using on frame 22 doesn't actually exist at that moment.
The likely candidates for the offending variable are foutput, btn_playagain, and btnback3. Check to make sure that they are on the stage at frame 22, and are spelt correctly.
You use output.text on frame 17, are you sure that it should be foutput.text on frame 22?

Error #2025: The supplied DisplayObject must be a child of the caller - Game Looping when after gotoAndStop

So ok Im somewhat new to flash im more of a java man myself but anyway I keep getting this error and all the solutions ive been find either don't work or they break the games collision
Here's the Code
stop();
import flash.utils.Timer;
import flash.utils.getDefinitionByName;
import flash.events.Event;
import flash.events.TimerEvent;
var playerobj:player;
var nextObject:Timer;
var objects:Array = new Array();
var score:int = 0;
const speed:Number = 9.0;
playerobj = new player();
playerobj.y = 650;
addChild(playerobj);
setNextObject();
addEventListener(Event.ENTER_FRAME, moveObjects);
function setNextObject()
{
nextObject = new Timer(1000+Math.random()*1000,1);
nextObject.addEventListener(TimerEvent.TIMER_COMPLETE,newObject);
nextObject.start();
}
function newObject(e:Event)
{
var newObject:AI;
newObject = new AI();
newObject.x = Math.random() * 480;
addChild(newObject);
objects.push(newObject);
setNextObject();
}
function moveObjects(e:Event)
{
for (var i:int=objects.length-1; i>=0; i--)
{
objects[i].y += speed;
if (objects[i].y > 800)
{
removeChild(objects[i]);
score = score + 10000;
objects.splice(i,1);
}
if (objects[i].hitTestObject(playerobj))
{
cleanUp();
}
}
playerobj.x = mouseX;
}
function cleanUp():void
{
while (this.numChildren > 0)
{
removeChildAt(0);
}
nextObject.stop();
gotoAndStop(4);
stop();
}
It must be somehow related to this problem but whenever gotoAndStop is called the game seems to loop around back into the frame not really sure why, Thanks for your help
In the cleanup function, right after declaring it, you should remove the ENTER_FRAME event listener. Also, I would stop the timer before removing childs and I would just remove the objects you added to stage dynamically. And the stop() in the cleanup function is redundant.
function cleanUp():void {
removeEventListener(Event.ENTER_FRAME, moveObjects);
nextObject.stop();
for(var i:uint = 0; i < objects.length; i++){
removeChild(objects[i]);
}
removeChild(playerObj)
gotoAndStop(4);
}
Also, it's better to keep minimal code in the timeline and move as much as you can in classes.
the error is in the cleanUp()
function moveObjects(e:Event)
{
for (var i:int=objects.length-1; i>=0; i--)
{
objects[i].y += speed;
if (objects[i].y > 800)
{
removeChild(objects[i]);
score = score + 10000;
objects.splice(i,1);
}
if (objects[i].hitTestObject(playerobj))
{
cleanUp();
}
}
//playerobj no more exists if cleanUp() is called, move this line above cleanUp();
//playerobj.x = mouseX;
//or inside cleanUp() put that line
//removeEventListener(Event.ENTER_FRAME, moveObjects);
}

AS3 loop movieClip based on set timer

I want to set a duration of time by hitting space bar twice. I then want a movieclip to play for that exact amount of time, then loop to play again at for that set amount of time, and so on. until I set a different amount of time by hitting the space bar twice again.
var beat:int;
var beatcount:int;
var tempopress:int;
var num:Number;
num = 0;
tempopress = 0;
stage.addEventListener(KeyboardEvent.KEY_DOWN,checker);
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
var myTimer:Timer=new Timer(20,0);
myTimer.addEventListener(TimerEvent.TIMER, stopWatch);
function stopWatch(event:TimerEvent):void {
beatcount = Number(myTimer.currentCount);
}
function checker(e:KeyboardEvent){
if(e.keyCode==Keyboard.SPACE){
if (tempopress == 0) {
trace('start');
beatcount = 0;
myTimer.reset();
myTimer.start();
tempopress = 1;
} else {
trace('stop');
myTimer.stop();
trace(beatcount);
tempopress = 0;
}
}
}
stage.addEventListener(Event.ENTER_FRAME, loopPlayback);
function loopPlayback() {
var loopTimer:Timer=new Timer(20,beatcount);
myTimer.addEventListener(TimerEvent.TIMER, loopWatch);
}
function loopWatch(event:TimerEvent):void {
if (MovieClipMan.currentFrame >= MovieClipMan.totalFrames ){
MovieClipMan.gotoAndStop(1);
} else {
MovieClipMan.nextFrame();
}
}
I know it's a mess haha. Please help! :]
I'd perhaps try something like this, which essentially is checking to see whether to do the loop or not each frame.
var timeStart:Number;
var loopDuration:Number;
var timeLastLoop:Number;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onKeyDown(e:KeyboardEvent):void {
if (e.keyCode == Keyboard.SPACE) {
if (!timeStart) { // First time SPACE is hit
timeStart = getTimer();
} else { // Second time SPACE is hit
loopDuration = getTimer() - timeStart; // set the loop duration
timeStart = NaN; // reset the start time
loop();
}
}
}
function onEnterFrame(e:Event):void {
if (loopDuration && timeLastLoop) {
if (getTimer() >= timeLastLoop + loopDuration) { // if it's time to loop
loop();
}
}
}
function loop():void {
timeLastLoop = getTimer();
someMovieClip_mc.gotoAndPlay(0);
}
First, use getTimer() to find the difference in time between space bar keypress.
Next, would be to stop creating a new Timer in every frame. It should be created outside of the enter frame handler. Then on the second keypress, you can set the delay property to the difference, and restart the timer.
The most important changes would be here:
if (tempopress == 0) {
trace('start');
myTimer.stop();
startTime = getTimer();
beatcount = 0;
tempopress = 1;
} else {
trace('stop');
myTimer.delay = getTimer() - startTime;
myTimer.reset();
myTimer.start();
tempopress = 0;
}
Then, the timer event handler can just send the MovieClip to frame 1.

Actionscript 3 Making the character to Jump

I am making a platformer game. But I am having issue because whenever I pressed the spacebar to jump, the character will stuck in the mid-air. However, I can resolved the problem by holding spacebar and the character will land.
The issue is at mainJump() located inside Boy class.
I seen many people solved the problem by using action timeline, but my main problem is, are there anyway I can solve the problem by using an external class?
Main class
package
{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.Timer;
import flash.text.*;
public class experimentingMain extends MovieClip
{
var count:Number = 0;
var myTimer:Timer = new Timer(10,count);
var classBoy:Boy;
//var activateGravity:gravity = new gravity();
var leftKey, rightKey, spaceKey, stopAnimation:Boolean;
public function experimentingMain()
{
myTimer.addEventListener(TimerEvent.TIMER, scoreUp);
myTimer.start();
classBoy = new Boy();
addChild(classBoy);
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressTheDamnKey);
stage.addEventListener(KeyboardEvent.KEY_UP, liftTheDamnKey);
}
public function pressTheDamnKey(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
leftKey = true;
stopAnimation = false;
}
if (event.keyCode == 39)
{
rightKey = true;
stopAnimation = false;
}
if (event.keyCode == 32)
{
spaceKey = true;
stopAnimation = true;
}
}
public function liftTheDamnKey(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
leftKey = false;
stopAnimation = true;
}
if (event.keyCode == 39)
{
rightKey = false;
stopAnimation = true;
}
if (event.keyCode == 32)
{
spaceKey = false;
stopAnimation = true;
}
}
public function scoreUp(event:TimerEvent):void
{
scoreSystem.text = String("Score : "+myTimer.currentCount);
}
}
}
Boy class
package
{
import flash.display.*;
import flash.events.*;
public class Boy extends MovieClip
{
var leftKeyDown:Boolean = false;
var upKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
var downKeyDown:Boolean = false;
//the main character's speed
var mainSpeed:Number = 5;
//whether or not the main guy is jumping
var mainJumping:Boolean = false;
//how quickly should the jump start off
var jumpSpeedLimit:int = 40;
//the current speed of the jump;
var jumpSpeed:Number = 0;
var theCharacter:MovieClip;
var currentX,currentY:int;
public function Boy()
{
this.x = 600;
this.y = 540;
addEventListener(Event.ENTER_FRAME, boyMove);
}
public function boyMove(event:Event):void
{
currentX = this.x;
currentY = this.y;
if (MovieClip(parent).leftKey)
{
currentX += mainSpeed;
MovieClip(this).scaleX = 1;
}
if (MovieClip(parent).rightKey)
{
currentX -= mainSpeed;
MovieClip(this).scaleX = -1;
}
if (MovieClip(parent).spaceKey)
{
mainJump();
}
this.x = currentX;
this.y = currentY;
}
public function mainJump():void
{
currentY = this.y;
if (! mainJumping)
{
mainJumping = true;
jumpSpeed = jumpSpeedLimit * -1;
currentY += jumpSpeed;
}
else
{
if (jumpSpeed < 0)
{
jumpSpeed *= 1 - jumpSpeedLimit / 250;
if (jumpSpeed > -jumpSpeedLimit/12)
{
jumpSpeed *= -2;
}
}
}
if (jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit)
{
jumpSpeed *= 1 + jumpSpeedLimit / 120;
}
currentY += jumpSpeed;
if (currentY >= stage.stageHeight - MovieClip(this).height)
{
mainJumping = false;
currentY = stage.stageHeight - MovieClip(this).height;
}
}
}
}
First of all, formalize your code, eliminating sassy things like 'pressTheDamnKey,' which doesn't even describe the function very well because a function cannot press a key. That is an event handler and should be named either keyDownHandler or onKeyDown, nothing else.
Secondly, you rarely want to do any actual work in event handlers beyond the immediate concerns of the event data. Instead call out to the function which does the actual work. A handler handles the event, then calls the code which does the work. This separates out concerns nicely for when you want something else to be able to also make the little boy animate besides the enterFrameHandler, like perhaps a mouse.
I can imagine your trace log is getting filled up pretty quickly with "Score" lines since your timer is firing 100 times a second (10 milliseconds per). I would change that to not fire on a timer, but to be refreshed when the score actually changes.
The problem with the jumping, aside from spaghetti code, is that you are basing his movements upon whether the key is pressed or not by saving the state of the key press in a variable and having him continually inspect it. This is bad for a couple of reasons: 1. he should not need to reach out to his environment for information, it should be given to him by whatever object owns him or by objects that are responsible for telling him and 2. It requires you to continually hold down the spacebar or he will stop moving, since he checks to see if it is being held down (see problem 1).
I will address all these issues below, leaving out the scoring, which is another matter altogether.
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
// Sprite is preferred if you are not using the timeline
public class Application extends Sprite
{
private var boy:Boy;
public function Application()
{
boy = new Boy();
addChild(boy);
boy.x = 600; // set these here, not in the boy
boy.y = 540;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler );
}
public function keyDownHandler(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case 32: boy.jump();
break;
case 37: boy.moveLeft();
break;
case 39: boy.moveRight();
break;
default:
// ignored
break;
}
}
public function keyUpHandler(event:KeyboardEvent):void
{
switch(event.keyCode)
{
// ignored for jumping (32)
case 37: // fall through
case 39: boy.stop();
break;
default:
// ignored
break;
}
}
}//class
}//package
package
{
import flash.display.*;
import flash.events.*;
// It is assumed that there is an asset in the library
// that is typed to a Boy, thus it will be loaded onto
// the stage by the owner
public class Boy extends Sprite
{
private var horzSpeed :Number = 0;
private var vertSpeed :Number = 0;
private var floorHeight :Number;
private var jumpHeight :Number;
private var amJumping :Boolean = false;
public function Boy()
{
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
public function moveLeft():void
{
horzSpeed = -1;
}
public function moveRight():void
{
horzSpeed = 1;
}
public function stop():void
{
horzSpeed = 0;
}
public function jump():void
{
if (amJumping) return;
floorHeight = y;
jumpHeight = floorHeight + 20;
vertSpeed = 2;
amJumping = true;
animateJump();
}
private function enterFrameHandler(event:Event):void
{
animate();
}
private function animate():void
{
x += horzSpeed;
if( amJumping )
{
animateJump();
}
}
// Doing a simple version for this example.
// If you want an easier task of jumping with gravity,
// I recommend you employ Greensock's superb
// TweenLite tweening library.
private function animateJump():void
{
y += vertSpeed;
if( y >= jumpHeight )
{
y = jumpHeight;
vertSpeed = -2;
}
else if( y <= floorHeight )
{
y = floorHeight;
amJumping = false;
}
}
}//class
}//package
Another way to approach this, and probably the better way long-term, is for the boy to not even be responsible for moving himself. Instead, you would handle that in the parent, his owner or some special Animator class that is responsible for animating things on schedule. In this even more encapsulated paradigm, the boy is only responsible for updating his own internal look based upon the outside world telling him what is happening to him. He would no longer handle jumping internally, but instead would be responsible for doing things like animating things he owns, like his arms and legs.
You've got a mainJumping variable that is only true while the jump is running. Why not just use that?
if (MovieClip(parent).spaceKey || mainJumping)
{
mainJump();
}

How to do you get an character to jump?

This is my fist time ever needing to use this for one of my games. I want to have the character jump. I have been trying to get this result for about an hour, but with no luck =( I am using AS3, and flash CS5.5. So far all my code does is make the character go left, and right based on keyboard input. Could someone please help?
Here is my code so far:
public class Dodgeball extends MovieClip
{
public var character:Character;
public var rightDown:Boolean = false;
public var leftDown:Boolean = false;
public var speed:Number = 3;
public var timer:Timer;
public function Dodgeball()
{
character= new Character();
addChild(character);
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, MyKeyUp);
timer = new Timer(24);
timer.addEventListener(TimerEvent.TIMER, moveClip);
timer.start();
}
public function myKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.RIGHT)
{
rightDown = true;
if(character.currentLabel != "walkingRight")
{
character.gotoAndStop ("walkingRight");
}
}
if (event.keyCode == Keyboard.LEFT)
{
leftDown = true;
if (character.currentLabel != "backingUp")
{
character.gotoAndStop("backingUp");
}
}
}
public function MyKeyUp(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.RIGHT)
{
character.gotoAndStop("standing");
rightDown = false;
}
if (event.keyCode == Keyboard.LEFT)
{
character.gotoAndStop("standingLeft");
leftDown = false;
}
}
public function moveClip(event:TimerEvent):void
{
if (rightDown)
{
character.x += speed;
}
if (leftDown)
{
character.x -=speed;
}
event.updateAfterEvent();
}
}
}
One method you can try is found here: http://www.actionscript.org/forums/showthread.php3?t=256009 Like your speed variable, grav determines the vertical position of the character.
var grav:Number = 10;
var jumping:Boolean = false;
var jumpPow:Number = 0;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(Event.ENTER_FRAME, update);
function onKeyDown(evt:KeyboardEvent):void
{
if(evt.keyCode == Keyboard.UP)
{
if(jumping != true)
{
jumpPow = -50;
jumping = true;
}
}
}
function update(evt:Event):void
{
if(jumping)
{
player_mc.y += jumpPow;
jumpPow += grav;
if(player_mc.y >= stage.stageHeight)
{
jumping = false;
player_mc.y = stage.stageHeight;
}
}
}
Edit: Jason's method is fine, but I'm not sure if it would be useful if you plan to have some kind of collision detection.
What I would do is create a motion tween of the character jumping. then call gotoAndPlay on that frame, and on the last frame of the tween put a stop, or a gotoAndStop on the "stationary" frame, or whatever frame represents a neutral position.
if (event.keyCode == Keyboard.SHIFT)
{
character.gotoAndPlay("simpleJump");
jumpDown = false;
}
This will give you the greatest animation control over the look and feel. You could also do it programmatically, but personally, I recommend against it. It will take less time to set it up, and you can tweak and refine the jump animations later. You could make several types of jump animations based on object near the target etc.
I would also change this stuff:
if(character.currentLabel != "walkingRight")
By defining a new function where you have all the rules for when and where something can be done, so that in your control logic, you just call
if(characterCan(character,"walkright")) ...
Where characterCan(String) is a method that check if this is possible. For instance, if you are jumping and shooting, you obviously cannot walk right, so in the end, you will have to start adding pieces of logic into those if statements and it's gonna become a cluttered mess.
A very simple approach is to have a vertical speed as well as a horizontal speed.
When the user presses "UP" or "JUMP", set y speed to a negative value and update it in your movieClip function. When the character gets to a certain height, reverse the speed.
Using gravity and acceleration looks better but this is a really good place to start. Look into kinematic equations to see how you would make the character accelerate.
public var originalY;
public function myKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.UP && vSpeed == 0)
{
originalY = character.y;
ySpeed = -1;
}
}
public function moveClip(event:TimerEvent):void
{
if (vSpeed != 0)
{
character.y += vSpeed;
/* make the character fall down after reaching max jump height */
if(originalY - character.y > jumpHeight) {
vSpeed = vSpeed * -1;
}
/* level the character after he's hit the ground (so he doesn't go through) */
else if(character.y >= originalY) {
character.y = originalY;
vSpeed = 0;
}
}
}