Basically I am making a game a lot like kitten-cannon (http://www.kittencannon.us/). What I have done is made a main menu structure using this code:
package {
import flash.display.*;
import flash.events.*;
import flash.ui.*;
public class Main extends MovieClip {
// Constants:
// Public Properties:
private static var stateChanged:Boolean = false;
private static var currState:Number = -1;
public static var keyStates:Array = new Array(new Boolean(false),new Boolean(false),new Boolean(false));
public static var game:Game;
public static var STATE_LOADING:Number = 0;
public static var MENU_STATE_MAIN:Number = 1;
public static var MENU_STATE_HELP:Number = 2;
public static var MENU_STATE_CREDITS:Number = 3;
public static var GAME_STATE_LOAD:Number = 4;
public static var GAME_STATE_RUN:Number = 5;
public static var GAME_STATE_END:Number = 6;
// Private Properties:
// Initialization:
public function Main() {
changeState(GAME_STATE_RUN);
addEventListener(Event.ENTER_FRAME, onLoop);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyIsDown);
stage.addEventListener(KeyboardEvent.KEY_UP,keyIsUp);
}
// Public Methods:
public function onLoop(evt:Event){
if(stateChanged){
deleteScreenContent();
initScreenContent();
}
}
public static function changeState(newState:Number):void{
currState = newState;
stateChanged = true;
}
public function deleteScreenContent(){
var numToLook:Number = this.numChildren;
var indexToLook:Number = 0;
for(var i:int = 0;i<numToLook;i++){
this.removeChildAt(indexToLook);
indexToLook++;
}
}
public function initScreenContent(){
switch(currState){
case STATE_LOADING:
break;
case MENU_STATE_MAIN:
break;
case MENU_STATE_HELP:
break;
case MENU_STATE_CREDITS:
break;
case GAME_STATE_LOAD:
break;
case GAME_STATE_RUN:
game = new Game();
addChild(game);
break;
case GAME_STATE_END:
break;
default:
break;
}
}
private function keyIsDown(evt:KeyboardEvent) {
switch (evt.keyCode) {
case Keyboard.UP :
keyStates[0] = true;
break;
case Keyboard.DOWN :
keyStates[1] = true;
break;
case Keyboard.SPACE :
keyStates[2] = true;
break;
}
}
private function keyIsUp(evt:KeyboardEvent) {
switch (evt.keyCode) {
case Keyboard.UP :
keyStates[0] = false;
break;
case Keyboard.DOWN :
keyStates[1] = false;
break;
case Keyboard.SPACE :
keyStates[2] = false;
break;
}
}
// Protected Methods:
}
}
this creates an instance of Game:
package{
import flash.display.*;
import flash.events.*;
public class Game extends MovieClip{
public static var screen:MovieClip = new MovieClip();
public var fgMC:ForegroundMovieClip;
public static var test:TestSymbol = new TestSymbol;
public function Game(){
init();
}
private function init(){
fgMC = new ForegroundMovieClip(stage);
test.x = 275;
test.y = 225;
addChild(screen);
screen.addChild(fgMC);
screen.addChild(test);
addEventListener(Event.ENTER_FRAME,onLoop);
}
public function onLoop(evt:Event){
test.rotation +=5;
}
}
}
my big problem is that with Main as my Document class the test MC will rotate and accelerate exponentially whereas if I simply have Game as my document class it will rotate as it should do i.e. smoothly and at 5 degrees each frame. WHY!? Please help, this is my first flash game and I am very inexperienced in flash game design. I have bee fine up until now.