Hi all,
I've got a problem with a MC I have in a game I'm making. Basically, it's a "flying in space" game, so the camera is looking down. The character, Dave, is floating in space and when the user presses an arrow button, he flies in that direction. I have a MC for Dave floating in space, and a seperate MC for Dave flying. Thanks to user Gibberish, I've created a holder MC that switches to the "inflight" MC when a key is down, and then back to the "static" MC when the button is released. My movement scripts are applied to the holder MC, named just dave. The problem I'm having is that my inflight MC, which contains two frames, is not looping. When the key is pressed, it loops for about a second, and then it just stops. The static MC loops fine, but the inflight does not.
Here's my script:
ActionScript Code:
dave._x = 400; // dave's X axis starting point
dave._y = 300;// dav'es Y axis starting point
speed = 4; // speed dave moves at
StageWidth = Stage.width; // width of stage -- old value was 800
StageHeight = Stage.height; // width of stage -- oldvalue was 600
// ---------------------------------------------------
// ------- SET LISTENERS
// ---------------------------------------------------
watchMouse = new Object();
watchMouse.onMouseMove = function() {
trace("The mouse X position is "+_xmouse);
trace("The mouse Y position is "+_ymouse);
};
// ----- Key Listener
watchKeyboard = new Object();
// on keyDown
watchKeyboard.onKeyDown = function () {
loadInFlight(); // load flying dave
dave.onEnterFrame = moveStuff; //run as onEnterFrame
}// End onKeyDown Function
// on keyUp
watchKeyboard.onKeyUp = function () {
loadStatic(); //load static dave
dave.onEnterFrame = null; // stop onEnterFrame
}// End onKeyUp Function
Key.addListener(watchKeyboard);
// ----- End Key Listener
// ---------------------------------------------------
// ------- END LISTENERS
// ---------------------------------------------------
// ---------------------------------------------------
// ------- SET FUNCTIONS
// ---------------------------------------------------
moveStuff = function() {
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
this._rotation = 90;
}
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
this._rotation = -90;
}
if (Key.isDown(Key.UP)) {
this._y -= speed;
this._rotation = 180;
}
if (Key.isDown(Key.DOWN)) {
this._y += speed;
this._rotation = 0;
}
if (this._x>StageWidth+(this._width/2)) {
this._x = 0-(this._width/2);
}
if (this._x<0-(this._width/2)) {
this._x = StageWidth+(this._width/2);
}
if (this._y>StageHeight+(this._height/2)) {
this._y = 0-(this._height/2);
}
if (this._y<0-(this._height/2)) {
this._y = StageHeight+(this._height/2);
}
}
//run this function to load Static Dave
loadStatic = function(){
dave.attachMovie("static","daveAction",0); //attach the static dave
}
loadStatic(); // this runs once at start of movie to load dave
//run this function to load inFlight Dave
loadInFlight = function(){
dave.attachMovie("inFlight","daveAction",0); // load flying dave
}
// ---------------------------------------------------
// ------- END FUNCTIONS
// ---------------------------------------------------
Anyone have any ideas why this is happening?
Thanks!!!