Argument error 1063 in AS3 - actionscript-3

so I have been working on a game called rock scissors paper lizard spock.
I got this error:
ArgumentError: Error #1063: Argument count mismatch on FlashGame_fla::MainTimeline/backtoBanana(). Expected 0, got 1.
this is my main code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.TextFormat;
rulesButton.addEventListener(MouseEvent.CLICK, toggleRule);
gameRules.addEventListener(MouseEvent.CLICK, toggleRule);
gameRules.visible = false;
gameRules.buttonMode = true;
function toggleRule(evt:MouseEvent):void
{
gameRules.visible = ! gameRules.visible;
}
menuButton.addEventListener(MouseEvent.CLICK, Click_backtoMain);
function Click_backtoMain(event:MouseEvent):void
{
gotoAndStop(213);
}
var isRolling:Boolean = false; //defalt is "false"
var pDieVal:int = 0;
var gDieVal:int = 0;
var pScore:int = 0;
var gScore:int = 0;
var pRolls:int = 0;
pDieMC.stop();
gDieMC.stop();
msgDisplay.text = "Click on the banana \nbutton to roll the die!";
pScoreDisplay.text = "0";
gScoreDisplay.text = "0";
rollButton.addEventListener(MouseEvent.CLICK, rollDie);
rollButton.addEventListener(MouseEvent.CLICK, dieRoll);
bananaWinLose.visible = false;
gameOverBananaMC.visible = false;
toMenuBtn.visible = false;
rollAgainBtn.visible = false;
function rollDie(evt:MouseEvent): void
{
if (isRolling)
{
//change flag to show die is NOT rolling
isRolling = false;
//change the label on the button to "BANANA!"
buttonDisplay.text = "BANANA!";
// STOP the dice animations
pDieVal= Math.ceil(Math.random() * pDieMC.totalFrames);
pDieMC.gotoAndStop(pDieVal);
gDieVal = Math.ceil(Math.random() * gDieMC.totalFrames);
gDieMC.gotoAndStop(gDieVal);
//set message display to an empty string
msgDisplay.text = "";
whoWon();
score();
}
else
{
//change flag to show die is rolling
isRolling = true;
//change the label on the button to "Stop"
buttonDisplay.text = "POPADAM!";
//PLAY the dice animations
pDieMC.play();
gDieMC.play();
//clear the message display
msgDisplay.text = "";
}
}
function whoWon():void
{
// is it a tie?
if (pDieVal == gDieVal)
{
msgDisplay.text = "Papoi?! It's a tie!";
}
else
{
// assume the player has lost
var hasPlayerWon:Boolean = false;
// determine if the player wins
if (pDieVal == 1 && (gDieVal == 4 || gDieVal == 5))
{
hasPlayerWon = true;
}
else if (pDieVal == 2 && (gDieVal == 1 || gDieVal == 5))
{
hasPlayerWon = true;
}
else if (pDieVal == 3 && (gDieVal == 1 || gDieVal == 2))
{
hasPlayerWon = true;
}
else if (pDieVal == 4 && (gDieVal == 3 || gDieVal == 2))
{
hasPlayerWon = true;
}
else if (pDieVal == 5 && (gDieVal == 3 || gDieVal == 4))
{
hasPlayerWon = true;
}
// display the results to the player
if (hasPlayerWon)
{
msgDisplay.text = "Yay! You win!";
}
else
{
msgDisplay.text = "Boo! Stuart wins!";
}
}
}
function dieRoll(evt:MouseEvent):void
{
trace("calculating pRolls");
if (pRolls == 20)
{
rpslsWon();
}
else
{
//increment pRolls by 1
pRolls++;
}
}
function score():void
{
//if player wins, his/her score increases by 1
if (msgDisplay.text == "Yay! You win!")
{
pScore = pScore + 1
pScoreDisplay.text = pScore.toString();
//if player loses, computer score increases by 1
}
else if (msgDisplay.text == "Boo! Stuart wins!")
{
gScore = gScore + 1
gScoreDisplay.text = gScore.toString();
//if neither wins, their scores remain unchange
}
else
{
pScore = pScore
gScore = gScore
}
}
function rpslsWon():void
{
gameOverBananaMC.visible = true;
bananaWinLose.visible = true;
bananaWinLose.text = "Kampai! You are totally bananas!! \nYour Score: " + pScore;
toMenuBtn.visible = true;
rollAgainBtn.visible = true;
toMenuBtn.addEventListener(MouseEvent.CLICK, Click_backtoMain);
rollAgainBtn.addEventListener(MouseEvent.CLICK, backtoBanana);
}
function backtoBanana():void
{
pScore = 0;
gotoAndStop("menu");
gotoAndStop("banana");
}
so the error appears in the function backtoBanana(), I can't seem to fix it.
Can someone help me? Thanks alot.

The callback function for the MouseEvent-listener will be passed a MouseEvent. Change
function backtoBanana():void
to
function backtoBanana(event:MouseEvent):void
just like your other callback function:
function Click_backtoMain(event:MouseEvent):void

Related

Character keeps falling when it shouldn't be

I am doing an assessment task for school in as3 and I have made a feature that will let the character fall if it is not standing on top of something but the boolean variable falling keeps being on when it is not supposed to. I have figured out that what causes it to stop for a short time and then fall again past what it is standing on is that the velocity valuable increases past the floor it is on so I reset the velocity value in the code in another spot but that does not solve the issue of the falling boolean being true when it is not supposed too.
I have put a comment at the temporary solution it is in the gameEngine function in the if(falling) statement
// Imports
import flash.events.KeyboardEvent;
import flash.events.Event;
// Constants that can be edited
const grav:Number = 0.05;
const jumpPow:Number = 15;
const walkingDistance = 50;
// Variables
var jumpVel:Number = jumpPow;
var velocity:Number = 0;
var dt:Number = 0;
var movingCount:Number = 0;
var newX:Number = 0;
var newY:Number = 0;
var charCornerHit:Number = 0; // 0 = TL 1 = TR 2 = BR 3 = BL (clockwise)
var jumping:Boolean = false;
var falling:Boolean = false;
var movingRight:Boolean = false;
var movingLeft:Boolean = false;
var hitDetVal:Boolean = false; // false
var floorHit:Boolean = false;
var object1Hit:Boolean = false;
var cCnrTL:Array = new Array(char.x, char.y);
var cCnrTR:Array = new Array(char.x + char.width, char.y);
var cCnrBR:Array = new Array(char.x + char.width, char.y + char.height);
var cCnrBL:Array = new Array(char.x, char.y + char.height);
var charCorners:Array = new Array(cCnrTL, cCnrTR, cCnrBR, cCnrBL); // Clockwise
addEventListener(Event.ENTER_FRAME, gameEngine);
function gameEngine(evt:Event):void{
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveCharacter);
charCorners[0][0] = char.x;
charCorners[0][1] = char.y;
charCorners[1][0] = char.x + char.width;
charCorners[1][1] = char.y;
charCorners[2][0] = char.x + char.width;
charCorners[2][1] = char.y + char.height;
charCorners[3][0] = char.x;
charCorners[3][1] = char.y + char.height;
//trace(char.y);
// Check if char is standing on something
// Supposed to only check when character is not falling
if (falling == false) {
//trace(char.y + char.height + 1)
hitDetection(0, char.y + char.height + 1)
if (hitDetVal == false) {
falling = true;
hitDetVal = false;
trace("not standing");
}
else {trace("standing on something");}
}
// Move char loop
if (movingRight){
if (movingCount == walkingDistance) {
movingCount = 0
movingRight = false;
} else {
char.x+=1
movingCount += 1;
}
} else if (movingLeft) {
if (movingCount == walkingDistance) {
movingCount = 0
movingLeft = false;
} else {
char.x-=1
movingCount += 1;
}
}
//trace(velocity)
if (falling) {
dt += 1
velocity = velocity + grav*dt
hitDetection(0, velocity)
if (hitDetVal) {
falling = false;
hitDetVal = false;
// TEMPORARY SOLUTION - Stopped character from falling past the floor but still ran falling condition
//velocity = 0;
//dt = 0;
if (floorHit) {
if (char.y < floor.y){
char.y = floor.y - char.height;
floorHit = false;
trace("Char Stopped falling")
}
} else if (object1Hit) {
if (char.y - char.height < object1.y){
char.y = object1.y - char.height;
object1Hit = false;
trace("Char Stopped falling")
}
}
} else {
char.y += velocity;
}
} else {
if (jumping) {
}
velocity = 0;
dt = 0;
}
}
function moveCharacter(event:KeyboardEvent):void{
if(event.keyCode == Keyboard.LEFT){
if(movingRight){
movingRight = false;
trace("STOPPED")
} else {
movingCount = 0
movingLeft = true;
trace("LEFT");
}
}
if(event.keyCode == Keyboard.RIGHT){
if(movingLeft){
movingLeft = false;
trace("STOPPED")
} else {
movingCount = 0
movingRight = true;
trace("RIGHT");
}
}
if(event.keyCode == Keyboard.UP){
jumping = true;
trace("UP");
}
}
function hitDetection(distX:Number, distY:Number) {
for (var i:uint = 0; i < charCorners.length; i++) {
newX = charCorners[i][0] + distX;
newY = charCorners[i][1] + distY;
if (floor.hitTestPoint(newX, newY, true)){
hitDetVal = true;
floorHit = true;
charCornerHit = i;
break;
} else if (object1.hitTestPoint(newX, newY, true)){
hitDetVal = true;
object1Hit = true;
charCornerHit = i;
break;
}
}
}```
It was a simple logic error occurring here
hitDetection(0, char.y + char.height + 1)
I had made adjustments for the location by adding char.y to the value when my hitDetection function already made an adjustment to each corner of my character. Only took ~3 hours to figure out

Flash - Pause Game ActionScript 3

I'm only a beginner and this code is somewhere in the internet that I just want to learn
This is a snake game, I want to pause a game using spacebar keyboard
I don't know how to pause a game someone please help
import flash.ui.*;
public class Snake extends MovieClip
{
private var _Paused:Boolean = false
private var score, life, framesElapsed:Number;
private var p1speedX, p1speedY:Number;
private var spacePressed, readyToMove, gotoWin, gotoLose:Boolean;
private var left,right,up,down:Boolean;
private var snakes:Array;
private var mcFood:Food;
public function Snake()
{
}
//All Start Functions
public function startMenu()
{
stop();
btnStartGame.addEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.addEventListener(MouseEvent.CLICK, gotoHowToPlay);
}
public function startHowToPlay()
{
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}
public function startWin()
{
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}
public function startLose()
{
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}
public function startGame()
{
score = 0;
life = 3;
framesElapsed = 0;
p1speedX = 1; //snakek starts moving right
p1speedY = 0;
up = false;
down = false;
left = false;
right = false;
spacePressed = false;
readyToMove = false;
gotoWin = false;
gotoLose = false;
snakes = new Array();
//Create 1st body part of snake and push it into the array
var snakeHead = new SnakePart();
snakeHead.x = 400;
snakeHead.y = 300;
snakes.push(snakeHead);
addChild(snakeHead);
addEventListener(Event.ENTER_FRAME,update);
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler);
stage.focus = this;
}
//All Goto Functions
private function gotoStartGame(evt:MouseEvent)
{
btnStartGame.removeEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.removeEventListener(MouseEvent.CLICK, gotoHowToPlay);
gotoAndStop("game");
}
private function gotoHowToPlay(evt:MouseEvent)
{
btnStartGame.removeEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.removeEventListener(MouseEvent.CLICK, gotoHowToPlay);
gotoAndStop("howtoplay");
}
private function gotoMenu(evt:MouseEvent)
{
btnBack.removeEventListener(MouseEvent.CLICK, gotoMenu);
gotoAndStop("menu");
}
private function keyDownHandler(evt:KeyboardEvent)
{
if (evt.keyCode == Keyboard.A)
{
//1st Player Left Key
left = true;
}
else if (evt.keyCode == Keyboard.D)
{
//1st Player Right Key
right = true;
}
if (evt.keyCode == Keyboard.W)
{
//1st Player Up Key
up = true;
}
else if (evt.keyCode == Keyboard.S)
{
//1st Player Down Key
down = true;
}
if (evt.keyCode == Keyboard.SPACE)
{
spacePressed = true;
}
}
private function keyUpHandler(evt:KeyboardEvent)
{
if (evt.keyCode == Keyboard.A)
{
left = false;
}
else if (evt.keyCode == Keyboard.D)
{
right = false;
}
else if (evt.keyCode == Keyboard.W)
{
up = false;
}
else if (evt.keyCode == Keyboard.S)
{
down = false;
}
if (evt.keyCode == Keyboard.SPACE)
{
spacePressed = false;
}
}
public function update(evt:Event)
{
handleUserInput();
handleGameLogic();
handleDraw();
if (gotoWin)
triggerGoToWin();
else if (gotoLose)
triggerGoToLose();
}
private function handleUserInput()
{
//Handle player 1 position
//if player wants to move left but snake is not
//already moving right
if (left && (p1speedX != 1))
{
p1speedX = -1;
p1speedY = 0;
}
//if player wants to move right but snake is not
//already moving left
else if (right && (p1speedX != -1 ))
{
p1speedX = 1;
p1speedY = 0;
}
//if player wants to move up but snake is not
//already moving down
else if (up && (p1speedY != 1))
{
p1speedY = -1;
p1speedX = 0;
}
else if (down && (p1speedY != -1))
{
p1speedY = 1;
p1speedX = 0;
}
if (spacePressed)
readyToMove = true;
}
private function handleGameLogic()
{
if (!readyToMove)
return;
framesElapsed++;
//Update the new position of the snake's head
if (framesElapsed % 2 == 0)
{
//Update motion of the snake's body
for (var i = snakes.length - 1; i >= 1; i--)
{
snakes[i].x = snakes[i-1].x;
snakes[i].y = snakes[i-1].y;
}
if (p1speedX > 0)
{
snakes[0].x += 20;
}
else if (p1speedX < 0)
{
snakes[0].x -= 20;
}
else if (p1speedY > 0)
{
snakes[0].y += 20;
}
else if (p1speedY < 0)
{
snakes[0].y -= 20;
}
//Check for collisions between the snake and its own body
for (var i = snakes.length - 1; i >= 1; i--)
{
if ((snakes[0].x == snakes[i].x) &&
(snakes[0].y == snakes[i].y))
{
collided();
break;
}
}
}
//Check for collisions between the snake and the walls
if (snakes[0].y < 0)
{
collided();
}
else if (snakes[0].x > 800)
{
collided();
}
else if (snakes[0].x < 0)
{
collided();
}
else if (snakes[0].y > 600)
{
collided();
}
//Add new food items
if (mcFood == null)
{
//Create a new food item
mcFood = new Food();
mcFood.x = Math.random() * 700 + 50;
mcFood.y = Math.random() * 500 + 50;
addChild(mcFood);
}
//Check for collisions between food item and Snake
if (mcFood != null)
{
if (snakes[0].hitTestObject(mcFood))
{
//Add score
score += 100;
if (score >= 5000)
gotoWin = true;
removeChild(mcFood);
mcFood = null;
//Add a body
var newPart = new SnakePart();
newPart.x = snakes[snakes.length-1].x;
newPart.y = snakes[snakes.length-1].y;
snakes.push(newPart);
addChild(newPart);
}
}
}
private function handleDraw()
{
//Handle display
if (!readyToMove)
txtHitSpaceBar.visible = true;
else
txtHitSpaceBar.visible = false;
txtScoreP1.text = String(score);
txtLife.text = String(life);
}
private function triggerGoToWin()
{
clearGame();
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop("win");
}
private function triggerGoToLose()
{
clearGame();
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop("lose");
}
//Misc Functions
private function resetGame()
{
//remove all food
removeChild(mcFood);
mcFood = null;
//remove all of snake body except first
for (var i = snakes.length - 1; i >= 1; i--)
{
removeChild(snakes[i]);
snakes.splice(i,1);
}
//Center the snake's head
snakes[0].x = 400;
snakes[0].y = 300;
readyToMove = false;
}
private function clearGame()
{
//remove all food
if (mcFood != null)
{
removeChild(mcFood);
mcFood = null;
}
//remove all of snake body
for (var i = snakes.length - 1; i >= 0; i--)
{
removeChild(snakes[i]);
snakes.splice(i,1);
}
}
private function collided()
{
life -= 1;
if (life > 0)
resetGame();
else
gotoLose = true;
}
}
}//end class
//end package
There are a few possibilities how to pause a game.
You already have a boolean variable called _Paused, this will help us to determine when to pause the execution of the game.
Change the contents of keyDownHandler(evt) to the following:
private function keyDownHandler(evt:KeyboardEvent)
{
...
//leave the if conditionals for movement as they are
if (evt.keyCode == Keyboard.SPACE)
{
if(_Pause == true){
_Pause = false;
}else{
_Pause = true;
}
}
}
The above code will toggle between a Paused state and the Game state. When the game first starts, the _Paused variable is false. Once you press Space on your keyboard, the if condition will check what state you need to be in. So at the very first time, _Paused will be set to true. if you press space again, it will set it to false again. Simple, right?
Now, you have an EventListener for ENTER_FRAME called update that executes for every frame. This function is responsible that things, well, work. You can see that it calls different functions that draw stuff on the screen or handle game logic. So, what would happen if you don't call this function? The game would stop. So we need a way to not call those functions when you are in your pause state. Again, this is very simple.
Change the contents of update(evt) to the following:
public function update(evt:Event)
{
if(_Paused == false){
handleUserInput();
handleGameLogic();
handleDraw();
if (gotoWin)
triggerGoToWin();
else if (gotoLose)
triggerGoToLose();
}
}
Now the functions will only be called when your _Paused variable is set to false.
I hope this helped you with your studying, although this is very basic stuff. Maybe you should try smaller steps first? Programming games can be pretty complex for beginner who have no experience with coding whatsoever.

Implicit coercion of a value of type flash.events:KeyboardEvent to an unrelated type flash.events:MouseEvent

how can I call a function of flash events : MouseEvent in flash events keyboardEvent function
I am a biggner in as3 please help
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyPressed);
function keyPressed(event:KeyboardEvent){
if (event.keyCode == Keyboard.ENTER)
{
if (keyMode == 0)
{
keyMode = 1;
**startFun(event);**
}
else if (keyMode == 1)
{
**checkfun(event);**
}
else if (keyMode == 2)
{
keyMode = 1;
**anotherPro(event);**
}
}
}
There is several ways, dispatch events, etc. I'll give you a simple example:
// or should be KEY_UP?
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedHandler, false, 0, true);
stage.addEventListener(MouseEvent.CLICK, exampleMouseClickHandler, false, 0, true);
function exampleMouseClickHandler(event:MouseEvent):void
{
//if necessary to pass any parameter, just need to change these mouseClickLogic() / keyPressLogic() methods
mouseClickLogic();
keyPressLogic();
}
function mouseClickLogic():void
{
//do something...
}
function keyPressedHandler(event:KeyboardEvent):void
{
//if necessary to pass any parameter, just need to change these mouseClickLogic() / keyPressLogic() methods
keyPressLogic();
mouseClickLogic();
}
function keyPressLogic():void
{
//to something...
}
You can use like that:
MouseEvent in flash events:
import flash.events.MouseEvent;
stage.addEventListener(MouseEvent.CLICK,clickStage);
stage.addEventListener(MouseEvent.MOUSE_UP,upStage);
stage.addEventListener(Event.MOUSE_LEAVE,leaveStage);
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownStage);
function clickStage(e:MouseEvent):void
{
trace("click Stage");
}
function upStage(e:MouseEvent):void
{
trace("up Stage");
}
function leaveStage(e:Event):void
{
trace("leave Stage");
}
function mouseDownStage(e:MouseEvent):void
{
trace("mouse Down Stage");
}
keyboardEvent function:
function reportKeyDown(event:KeyboardEvent):void
{
trace("Key Pressed: " + String.fromCharCode(event.charCode) + " (character code: " + event.charCode + ")");
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
I thank all those who tried to help me
this is my program without any error the error which I made before is in this code instead of Event
I typed MousEvent
function startFun(evt:Event):void
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.Event;
var elapsedTime:Number;
var NumOfProplem:Number;
var PropSolved:Number;
var completeSet:Boolean;
answerbox.restrict = "0-9";
ProplemBox.restrict = "0-9";
mult2.restrict = "?";
mult1.restrict = "?";
var keyMode:Number = 0;
stage.focus = ProplemBox;
bt1.visible = false;
bt2.visible = false;
//////////////////////////////
btnstart.addEventListener(MouseEvent.CLICK, startFun);
function startFun(evt:Event):void {
if (ProplemBox.text == "") {
stage.focus = ProplemBox;
return;
}
bt1.visible = true;
bt2.visible = true;
NumOfProplem = Number(ProplemBox.text);
PropSolved = 0;
completeSet = false;
elapsedTime = getTimer();
keyMode = 1;
anotherPro(evt);
}
///////////////////////////////
stage.focus = answerbox;
answerbox.setSelection(0,3);
}
/////////////////
bt1.addEventListener(MouseEvent.CLICK,checkfun);
function checkfun(evt:Event):void
{
var x:Number = parseInt(mult1.text);
var y:Number = parseInt(mult2.text);
var z:Number = parseInt(answerbox.text);
if ((x*y )== z){
messagebox.text = "Right";
PropSolved++;
if (PropSolved >= NumOfProplem ){
keyMode = 3;
endGameReport();
}
else{
keyMode = 2;
}
}
else
{
messagebox.text = "Wrong";
stage.focus = answerbox;
answerbox.setSelection(0,3);
}
}
function endGameReport():void{
elapsedTime = (getTimer() - elapsedTime);
stage.focus = ProplemBox;
ProplemBox.setSelection(0,2);
bt1.visible = false;
bt2.visible = false;
messagebox.text = "You completed" + NumOfProplem + "Proplems in"
+ Math.floor(elapsedTime/1000) + "Second";
}
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyPressed);
function keyPressed(evt:KeyboardEvent){
if (evt.keyCode == Keyboard.ENTER)
{
if (keyMode == 0)
{
keyMode = 1;
startFun(evt);
}
else if (keyMode == 1)
{
checkfun(evt);
}
else if (keyMode == 2)
{
keyMode = 1;
anotherPro(evt);
}
}
}

1084: Syntax error: expecting rightbrace before end of program

So I keep getting this error, debugger wont run but rather just shows this error in a compiler box.
Thing has been driving me crazy for days now so I decided to post it here.
So it says:
Scene 1, Layer 'powerups', Frame 1 1084: Syntax error: expecting rightbrace before end of program.
I designed my code so that the "powerups" layer contains only "powerup" functions,
heres the code from "Powerups" layer:
//this code holds the powerups
function extraCoins():void
{
coins = coins + 1000;
}
function doubleCoins():void
{
doubCoins = true;
}
function hyperBoostD():void
{
Boost = 600;
playerSpeed = playerSpeed + 150;
player.y = player.y + 300;
colBoolean = false;
hyperBoost.push(Boost);
}
function BoostD():void
{
Boost = 200;
playerSpeed = playerSpeed + 100;
player.y = player.y + 200;
colBoolean = false;
boost.push(Boost);
}
function multiplierDone():void
{
multiplier++;
}
function multiplierDtwo():void
{
multiplier = multiplier + 2;
}
function watchOutD():void
{
watchOut = true;
watchOutT = 600;
}
function blowOutD():void
{
blowOut = true;
blowOutT = 100;
}
function planeD():void
{
planeT = 600;
colBoolean = false;
}
function havenD():void
{
havenT = 200;
coinMake = 20;
}
function badBirdD():void
{
birdT = 600;
birdSet = 10;
}
function tricksterD():void
{
tricksterT = 600;
trickster = true;
}
function rampageD():void
{
rampageT = 600;
rampage = true;
pplStat = true;
var tempWatchoutPPL:MovieClip;
tempWatchoutPPL = new peopleWatchout();
tempWatchoutPPL.y = stage.stageHeight /2;
tempWatchoutPPL.x = stage.stageWidth /2;
addChild(tempWatchoutPPL);
signs.push(tempWatchoutPPL);
}
function helpPPLD():void
{
helpPPLT= 600;
helpPPL = true;
var tempHelpPPL:MovieClip;
tempHelpPPL = new savePpl();
tempHelpPPL.y = stage.stageHeight /2;
tempHelpPPL.x = stage.stageWidth /2;
addChild(tempHelpPPL);
signs.push(tempHelpPPL);
}
And here is my main code :
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.engine.SpaceJustifier;
import flashx.textLayout.operations.MoveChildrenOperation;
import flash.utils.Timer;
import flashx.textLayout.accessibility.TextAccImpl;
/*
CODE BY:
START DATE: 12.06.2013.
FINISH DATE: TBA
NOTE: My secound video game ever.
BUGs:
-obsticle collison stops working after some time playing
-passing coin gives you more than 5 coins
*/
/***..........................VARs.........................................................................***/
var STATE_START:String="STATE_START";
var STATE_START_PLAYER:String="STATE_START_PLAYER";
var STATE_PLAY:String="STATE_PLAY";
var STATE_END:String="STATE_END";
var gameState:String;
//Player
var player:MovieClip;
var playerSpeed:Number;
var speedLimit:Number;
var speedLimitInc:Number;
//score
var score:Number= 1;
var scoreInc:Number= 1;
//coins
var coins:Number= 1;
var balance:Number;
var coinCount:Number= 1;
var Coins:Array;
var doubCoins:Boolean = false;
var multiplier:int = 1;
var coinMake:Number = 60;
//distance
var meters:Number= 1;
var distance:Number= 1;
//holds drops
var drops:Array;
//terrain
//decides spawning time
var GenS:Number=1;
//holds terrain
var terrain:Array;
//boost
//holds the speedBoosts that are happening
var boost:Array;
//holds boost dysp obj.
var booost:Array;
//holds speedBoost duration
var Boost:Number;
//collision on/off
var colBoolean:Boolean=true;
var hyperBoost:Array;
//obsticles
var obsticles:Array;
//other
var level:Number= 1;
var levelCount:Number= 1;
var birdArray:Array;
var jumpState:Boolean = false;
var jumpStateT:int;
var jumps:Array;
//powerUps
var watchOut:Boolean = false;
var watchOutT:int;
var blowOut:Boolean = false;
var blowOutT:int;
var planeT:int;
var birdT:int;
var birdSet:int = 300;
var havenT:int;
var trickster:Boolean = false;
var tricksterT:int;
var ppl:Array;
//pplStat tells if ppl are getting hurt or need help, if ture, it means you are gonna run them over
var pplStat:Boolean = true;
var rampage:Boolean;
var rampageT:int;
var helpPPLT:int;
var helpPPL:Boolean;
var signs:Array;
/***.......................Display SETUP...................................................................***/
homeScreen.visible = true;
gamePlay.visible = false;
endScreen.visible = false;
/***........................Start Screen...................................................................***/
homeScreen.play_BTN.addEventListener(MouseEvent.CLICK, clickPlay);
homeScreen.settings_BTN.addEventListener(MouseEvent.CLICK, clickSettings);
function clickPlay(event:MouseEvent):void
{
//Move main screen from stage
homeScreen.visible = false;
//Begin loading the game
gameState = STATE_START;
trace (gameState);
addEventListener(Event.ENTER_FRAME, gameLoop);
}
function clickSettings(event:MouseEvent):void
{
//Move main screen from stage
homeScreen.visible = false;
//settingsScreen.visible...
}
/***...........................Game LOOP...................................................................***/
function gameLoop(e:Event):void
{
switch(gameState)
{
case STATE_START:
startGame();
break;
case STATE_START_PLAYER:
startPlayer();
break;
case STATE_PLAY:
playGame();
break;
case STATE_END:
endGame();
break;
}
}
/***...............STATE_START.............................................................................***/
function startGame():void
{
level = 1;
playerSpeed = 1;
speedLimit = 10;
speedLimitInc = 1;
//Graphics
//coins
Coins = new Array();
//player icon
player = new Player();
//start obsticles array
obsticles = new Array();
//holds terrain (speedUps, jupms, etc)
terrain = new Array();
//holds speedUps
boost = new Array();
booost = new Array();
hyperBoost = new Array();
//other
drops = new Array();
birdArray = new Array();
jumps = new Array();
ppl = new Array();
signs = new Array();
gameState = STATE_START_PLAYER;
trace(gameState);
}
/***....................STATE_START_PLAYER................................................................***/
function startPlayer():void
{
//start the player
//set possition of player
player.y = player.height + 10;
addChild(player);
addEventListener(Event.ENTER_FRAME, movePlayer);
//changing screens
//start game
gameState = STATE_PLAY;
trace(gameState);
}
//player controll
function movePlayer(e:Event):void
{
//mouse\touch recognition
player.x = stage.mouseX;
//making sure player does not move out of the stage
if (player.x < 0)
{
player.x = 0;
}
if (player.x > (stage.stageWidth - 2/player.width))
{
player.x = stage.stageWidth + 2/player.width;
}
}
/***............................STATE_PLAY................................................................***/
function playGame():void
{
if (watchOutT <= 0) {watchOut = false}
if (blowOutT <= 0) {blowOut = false}
if (planeT <= 0) {colBoolean = true}
if (tricksterT <= 0) {trickster= false}
if (havenT <= 0) {coinMake = 60}
if (birdT <= 0) {birdSet = 300}
if (planeT >= 0) {planeT--} birdT
if (havenT >= 0) {havenT--}
if (birdT >= 0) {birdT--}
if (tricksterT >= 0) {tricksterT--}
speedUp();
metersCount();
scoreCount();
makeCoins();
moveCoins();
makeTerrain();
moveDrop();
makeBird();
moveBird();
moveJump();
moveSigns();
movePPL();
stunts();
//speed boost
moveSpeedBoost();
//obsticles
moveObsticle();
}
function metersCount():void
{
meters = meters + playerSpeed;
distance = meters / 50;
if (distance >= 1000 && distance <= 1200)
{
levelCount= 1000;
level = 2;
}
if (distance >= (levelCount + 1000) && distance <= (levelCount + 1200))
{
level++;
levelCount= levelCount + 1000;
}
trace("level", level);
trace("meters", meters);
trace("coins", coins);
trace("distance", distance);
}
function scoreCount():void
{
if (scoreInc >= 30) { score++; scoreInc=1; trace("-score", score); }
scoreInc++
}
function makeCoins():void
{
trace("coinCount", coinCount);
if (coinCount == coinMake)
{
var tempCoin:MovieClip;
//generate enemies
tempCoin = new Coin();
tempCoin.speed = playerSpeed;
tempCoin.x = Math.round(Math.random()*400);
tempCoin.y = stage.stageHeight;
addChild(tempCoin);
Coins.push(tempCoin);
coinCount = 1;
}
coinCount++;
}
function moveCoins():void
{
var j:int;
var tempCoin:MovieClip;
for(var i:int = Coins.length-1; i>=0; i--)
{
tempCoin = Coins[i];
tempCoin.y = tempCoin.y - playerSpeed;
}
//testion colision with the player and screen out
if (tempCoin != null)
{
if (tempCoin.y > stage.stageHeight)
{
removeCoin(i);
}
if (tempCoin.hitTestObject(player))
{
if (i != j && doubCoins == false) {coins = coins + 5; j = i;}
if (i != j && doubCoins == true) {coins = coins + 10; j = i;}
removeCoin(i);
}
}
}
function speedUp():void
{
trace ("speed", playerSpeed);
//checks if any boosts are on
var k:Boolean;
//making speed limit
if (playerSpeed < speedLimit)
{
playerSpeed ++;
if (k == true) {j++}
}
//increasing speed limit
if (speedLimitInc == 100)
{
speedLimit ++;
speedLimitInc = 1;
}
speedLimitInc ++;
var j:Number;
j = playerSpeed;
for (var i:int = boost.length-1; i>=0; i--)
{
if (tempBoostN >= 0)
{k = true; colBoolean = true;}
else
{
k = false;
player.y = player.height + 30;
}
var tempBoostN = boost[i];
if (playerSpeed >= j)
{
if (tempBoostN >= 150)
{
playerSpeed = playerSpeed -1;
} else if (tempBoostN <= 150 && tempBoostN >= 30) {
playerSpeed = playerSpeed - 2;
}
tempBoostN--;
}
}
var l:Number;
l = playerSpeed;
for (var i:int = boost.length-1; i>=0; i--)
{
if (tempBoostN >= 0)
{k = true; colBoolean = true;}
else
{
k = false;
player.y = player.height + 30;
}
var tempBoostH = hyperBoost[i];
if (playerSpeed >= l)
{
if (tempBoostH >= 150)
{
playerSpeed = playerSpeed -1;
} else if (tempBoostN <= 150 && tempBoostH >= 30) {
playerSpeed = playerSpeed - 2;
}
tempBoostH--;
}
}
}
function makeBos():void
{
var tempBoost:MovieClip;
tempBoost = new speedPod();
if (tempBoost != null)
{
tempBoost.y = stage.stageHeight;
tempBoost.x = Math.round(Math.random()*400);
booost.push(tempBoost);
var i = getChildIndex(player);
addChild(tempBoost);
setChildIndex (tempBoost, i);
}
}
function moveSpeedBoost():void
{
var tempBoost:MovieClip;
for(var i:int = booost.length-1; i>=0; i--)
{
tempBoost = booost[i];
tempBoost.y = tempBoost.y - playerSpeed;
}
//test if Boost is off-stage and set it to remove
if (tempBoost != null && tempBoost.y < stage.stageHeight)
{
removeSpeedBoost(i);
}
//player-Boost colision
if (tempBoost != null && tempBoost.hitTestObject(player))
{
Boost = 200;
playerSpeed = playerSpeed + 100;
player.y = player.y + 200;
colBoolean = false;
boost.push(Boost);
}
}
function makeTerrain():void
{
if (GenS == 29)
{
GenS = 1;
var genType:Number = Math.floor(Math.random()*100);
//POWERUPS
//handling watchout powerup
if (watchOut = true){watchOutT--; makeObs();}
//handling blowout powerup
if (blowOut = true){blowOutT--;}
//handling trickster powerup
if (trickster = true){makeJump();}
//handling rampage powerup
if (rampage = true){makePPL(0); rampageT--;}
//handling hurtPPL powerup
if (hurtPPL = true){makePPL(1); hurtPPLT--;}
//general spawning
if (genType >= 1 && genType <=20 && watchOut == false && blowOut == false && trickster == false)
{
trace("makeObs");
makeObs();
}else if (genType >= 20 && genType <=60 && watchOut == false && blowOut == false && trickster == false)
{
trace("makeBos");
makeBos();
}else if (genType >= 60 && genType <=65 && watchOut == false && blowOut == false && trickster == false)
{
trace("makeDrop");
makeDrop();
}else if (genType >= 65 && genType <=100 && watchOut == false && blowOut == false && trickster == false)
{
trace("make jump");
makeJump();
}
}
GenS++;
}
function makeObs():void
{
var tempObs:MovieClip;
//determining the type of an obsticle
var typeObs:Number = Math.floor(Math.random()*3);
switch (typeObs)
{
case 0:
tempObs = new wLog();
break;
case 1:
tempObs = new Spill();
break;
case 2:
tempObs = new wTree();
break;
}
if (tempObs != null)
{
tempObs.y = stage.stageHeight;
tempObs.x = Math.round(Math.random()*400);
addChild(tempObs);
obsticles.push(tempObs);
}
}
function makePPL():void
{
var tempPPL:MovieClip;
if (hurtPPL = true)
{tempPPL = new personHurt();}
else {tempPPL = new person();}
tempPPL.y = stage.stageHeight;
tempPPL.x = Math.round(Math.random()*400);
addChild(tempPPL);
ppl.push(tempPPL);
}
function movePPL():void
{
//move enemies
var tempPPL:MovieClip;
for(var i:int = ppl.length-1; i>=0; i--)
{
tempPPL = ppl[i];
tempPPL.y = tempPPL.y - playerSpeed;
}
//test if obsticle is off-stage and set it to remove
if (tempPPL != null && tempPPL.y < stage.stageHeight)
{
removePPL(i);
}
//player-obsticle colision
if (tempPPL != null && tempPPL.hitTestObject(player) && hurtPPL = true)
{
score = score + 1000;
coins = coins + 1000;
var tempSaved:MovieClip;
tempSaved = new savedPerson();
tempSaved.y = stage.stageHeight /2;
tempSaved.x = stage.stageWidth /2;
addChild(tempSaved);
signs.push(tempSaved);
trace ("person saved");
removePPL(i);
} else if (tempPPL != null && tempPPL.hitTestObject(player))
{
score = score - 1000;
var tempRanOver:MovieClip;
tempRanOver = new ranOver();
tempRanOver.y = stage.stageHeight /2;
tempRanOver.x = stage.stageWidth /2;
addChild(tempRanOver);
signs.push(tempRanOver);
trace ("ran over a person");
removePPL(i);
}
}
function moveSigns():void
{
//move enemies
var tempSign:MovieClip;
for(var i:int = signs.length-1; i>=0; i--)
{
tempSign = signs[i];
tempSign.y = tempSign.y - playerSpeed;
}
//test if obsticle is off-stage and set it to remove
if (tempSign != null && tempSign.y < stage.stageHeight)
{
removeSign(i);
}
}
function makeDrop():void
{
var tempDrop:MovieClip;
tempDrop = new Drop();
tempDrop.y = stage.stageHeight;
tempDrop.x = Math.round(Math.random()*400);
addChild(tempDrop);
drops.push(tempDrop);
}
function moveDrop():void
{
//move enemies
var tempDrop:MovieClip;
for(var i:int = drops.length-1; i>=0; i--)
{
tempDrop = drops[i];
tempDrop.y = tempDrop.y - playerSpeed;
}
//test if obsticle is off-stage and set it to remove
if (tempDrop != null && tempDrop.y < stage.stageHeight)
{
removeDrop(i);
}
//player-obsticle colision
if (tempDrop != null && tempDrop.hitTestObject(player))
{
powerUp();
}
}
function makeBird():void
{
if (distance >= 200)
{
var chance:Number = Math.floor(Math.random()*birdSet);
if (chance <= 1 + level)
{
var tempBird:MovieClip;
//generate enemies
tempBird = new BirdO();
tempBird.speed = 60 + playerSpeed;
tempBird.x = Math.round(Math.random()*400);
addChild(tempBird);
birdArray.push(tempBird);
}
}
}
function moveBird():void
{
var tempBird:MovieClip;
for(var i:int = birdArray.length-1; i>=0; i--)
{
tempBird = birdArray[i];
tempBird.y -= tempBird.speed;
}
if (tempBird != null)
{
if (tempBird.y > stage.stageHeight)
{
removeBird(i);
}
if (tempBird.hitTestObject(player))
{
gameState = STATE_END;
}
}
}
function powerUp():void
{
var dropType:Number = Math.floor(Math.random()*16);
switch (dropType)
{
case 0:
trace("extra coins");
extraCoins();
break;
case 4:
trace("2x coins");
doubleCoins();
break;
case 2:
trace("hyper boost");
hyperBoostD();
break;
case 3:
trace("boost");
BoostD();
break;
case 4:
trace("multiplier 1x");
multiplierDone();
break;
case 5:
trace("multiplier 2x");
multiplierDtwo();
break;
case 6:
trace("watch out!");
watchOutD();
break;
case 7:
trace("blowout");
blowOutD();
break;
case 8:
trace("plane");
planeD();
break;
case 9:
trace("haven");
havenD();
break;
case 10:
trace("bad bird");
badBirdD();
break;
case 11:
trace("trickster");
tricksterD();
break;
case 12:
trace("rampage");
rampageD();
break;
case 13:
break;
case 14:
break;
case 15:
break;
case 16:
break;
}
}
function makeJump():void
{
var tempJump:MovieClip;
tempJump = new Jump();
tempJump.speed = playerSpeed;
tempJump.x = Math.round(Math.random()*400);
addChild(tempJump);
jumps.push(tempJump);
}
function moveJump():void
{
var tempJump:MovieClip;
for(var i:int = jumps.length-1; i>=0; i--)
{
tempJump = jumps[i];
tempJump.y = tempJump.y - playerSpeed;
}
//test if obsticle is off-stage and set it to remove
if (tempJump != null && tempJump.y < stage.stageHeight)
{
removeJump(i);
}
//player-obsticle colision
if (tempJump != null && tempJump.hitTestObject(player))
{
jumpState = true;
jumpStateT = 100;
}
}
function stunts():void
{
if (jumpStateT >= 0)
{
jumpStateT--;
jumpState = true;
}
if (jumpState = true)
{
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler);
}
}
function fl_SwipeHandler(event:TransformGestureEvent):void
{
switch(event.offsetX)
{
// swiped right
case 1:
{
// My code
trace ("side flip");
score = score + 1000;
coins = coins + 500;
break;
}
// swiped left
case -1:
{
// My code
trace ("barell roll");
score = score + 1000;
coins = coins + 500;
break;
}
}
switch(event.offsetY)
{
// swiped down
case 1:
{
trace ("front flip");
score = score + 1000;
coins = coins + 500;
break;
}
// swiped up
case -1:
{
trace ("side flip");
score = score + 1000;
coins = coins + 500;
break;
}
}
}
function moveObsticle():void
{
//move enemies
var tempObs:MovieClip;
for(var i:int = obsticles.length-1; i>=0; i--)
{
tempObs = obsticles[i];
tempObs.y = tempObs.y - playerSpeed;
}
//test if obsticle is off-stage and set it to remove
if (tempObs != null && tempObs.y < stage.stageHeight)
{
removeObsticle(i);
}
//player-obsticle colision
if (tempObs != null && tempObs.hitTestObject(player))
{
gameState = STATE_END;
}
}
/*REMOVING BS FROM STAGE*/
//remove obsticle
function removeObsticle(idx:int):void
{
if(idx >= 0)
{
removeChild(obsticles[idx]);
obsticles.splice(idx, 1);
}
}
function removeTer(idx:int):void
{
if(idx >= 0)
{
removeChild(terrain[idx]);
terrain.splice(idx, 1);
}
}
function removeSpeedBoost(idx:int):void
{
if(idx >= 0)
{
removeChild(boost[idx]);
boost.splice(idx, 1);
}
}
function removeCoin(idx:int):void
{
if(idx >= 0)
{
removeChild(Coins[idx]);
Coins.splice(idx, 1);
}
}
function removeDrop(idx:int):void
{
if(idx >= 0)
{
removeChild(drops[idx]);
drops.splice(idx, 1);
}
}
function removeBird(idx:int):void
{
if(idx >= 0)
{
removeChild(birdArray[idx]);
birdArray.splice(idx, 1);
}
function removeJump(idx:int):void
{
if(idx >= 0)
{
removeChild(jumps[idx]);
jumps.splice(idx, 1);
}
}
function removePPL(idx:int):void
{
if(idx >= 0)
{
removeChild(ppl[idx]);
ppl.splice(idx, 1);
}
}
function removeSigns(idx:int):void
{
if(idx >= 0)
{
removeChild(signs[idx]);
signs.splice(idx, 1);
}
}
/***.........................STATE_END....................................................................***/
function endGame():void
{
gamePlay.visible = false;
endScreen.visible = true;
}
I have checked times and times again for any syntax missing and have failed to find a problem.
I have seen a guy asking a question here about similar error and it turns out its not eaven a syntax error, he still didnt resolve the problem.
I have also indented all the code properly and eaven used "auto format" in flash pro cs6 to see if it screams any syntax errors and it didnt.
Im making a mobile game so all the code is running in the following environment:
AIR 3,2 for android
And of course as 3.0
Thanks in advance.
You are missing a close bracket } after this function: Try to read your code carefully before asking. Pretty easy to notice :)
function removeBird(idx:int):void
{
if(idx >= 0)
{
removeChild(birdArray[idx]);
birdArray.splice(idx, 1);
}

addEventListener() isn't detecting KEY_UP nor KEY_DOWN

My full code is
import flash.events.KeyboardEvent;
import flash.events.Event;
//init some variables
var speedX = 0;
var speedY = 0;
msg.visible = false;
var curLevel = 2;
var level = new Array();
var flagVar;
var won = false;
//Adding level platforms
for(var i = 0; i < numChildren; i++) {
if(getChildAt(i) is platform) {
level.push(getChildAt(i).getRect(this));
}
if(getChildAt(i) is flag) { flagVar = getChildAt(i).getRect(this); }
}
//Checking key presses
var kUp = false;
var kDown = false;
var kLeft = false;
var kRight = false;
var kSpace = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, kD);
stage.addEventListener(KeyboardEvent.KEY_UP, kU);
function kD(k:KeyboardEvent) {
trace("Key down - " + k.keyCode);
if(k.keyCode == 32) { kSpace = true; }
if(k.keyCode == 37 ) { kLeft = true; }
if(k.keyCode == 38) { kUp = true; }
if(k.keyCode == 39) { kRight = true; }
}
function kU(k:KeyboardEvent) {
trace("Key up - " + k.keyCode);
if(k.keyCode == 32) { kSpace = false; }
if(k.keyCode == 37) { kLeft = false; }
if(k.keyCode == 38) { kUp = false; }
if(k.keyCode == 39) { kRight = false; }
}
addEventListener(Event.ENTER_FRAME, loopAround);
function loopAround(e:Event) {
//horizontal movement
if(kLeft) {
speedX = -10;
} else if(kRight) {
speedX = 10;
} else {
speedX *= 0.5;
}
player.x += speedX;
//horizontal collision checks
for(var i = 0; i < level.length; i++) {
if(player.getRect(this).intersects(level[i])) {
if(speedX > 0) {
player.x = level[i].left - player.width;
}
if(speedX < 0) {
player.x = level[i].right;
}
speedX = 0;
}
}
//vertical movement
speedY += 1;
player.y += speedY;
var jumpable = false;
//Vertical collision
for(i = 0; i < level.length; i++) {
if(player.getRect(this).intersects(level[i])) {
if(speedY > 0) {
player.y = level[i].top - player.height;
speedY = 0;
jumpable = true;
}
if(speedY < 0) {
player.y = level[i].bottom;
speedY *= -0.5;
}
}
}
//JUMP!
if((kUp || kSpace) && jumpable) {
speedY=-20;
}
//Moving camera and other
this.x = -player.x + (stage.stageWidth/2);
this.y = -player.y + (stage.stageHeight/2);
msg.x = player.x - (msg.width/2);
msg.y = player.y - (msg.height/2);
//Checking win
if(player.getRect(this).intersects(flagVar)) {
msg.visible = true;
won = true;
}
//Check for next level request
if(kSpace && won) {
curLevel++;
gotoAndStop(curLevel);
won = false;
}
}
The section in question is
//Checking key presses
var kUp = false;
var kDown = false;
var kLeft = false;
var kRight = false;
var kSpace = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, kD);
stage.addEventListener(KeyboardEvent.KEY_UP, kU);
function kD(k:KeyboardEvent) {
trace("Key down - " + k.keyCode);
if(k.keyCode == 32) { kSpace = true; }
if(k.keyCode == 37 ) { kLeft = true; }
if(k.keyCode == 38) { kUp = true; }
if(k.keyCode == 39) { kRight = true; }
}
function kU(k:KeyboardEvent) {
trace("Key up - " + k.keyCode);
if(k.keyCode == 32) { kSpace = false; }
if(k.keyCode == 37) { kLeft = false; }
if(k.keyCode == 38) { kUp = false; }
if(k.keyCode == 39) { kRight = false; }
}
This was working fine last night, but today I moved it to a new keyframe and now it's not working. I'm not getting any errors (even if I debug). It just won't move the character or even show up in output.
I'm still quite new to as3, so I don't really know what to do.
Thanks in advance.
Edit: After playing with it a bit, I've found out that the reason it's not working is due to the menu. The menu has a single button and two text elements, which are fine. The code that I'm using on the menu is this:
import flash.events.MouseEvent;
stop();
var format:TextFormat = new TextFormat();
format.size = 26;
format.bold = true;
playGameButton.setStyle("textFormat", format);
stage.addEventListener(MouseEvent.CLICK, playGame);
function playGame(e:MouseEvent) {
if(e.target.name == "playGameButton") {
gotoAndStop(2);
}
}
If I use just gotoAndStop(2); it works fine, but with everything else it just goes to the second frame, and nothing else works after that.
Edit #2: I've narrowed it down even farther to the if statement itself.
if(e.target == playGameButton)
if(e.target.name == "playGameButton")
Both of those don't work. If I just remove the if statement all together it works perfectly fine.
there seems to be aproblem with this lines
if(getChildAt(i) is platform)
leads to error 1067: Implicit coercion of a value of type flash.display:MovieClip to an unrelated type Class
the rest of the code seems to be just fine
Try disabling your buttons mouseChildren.
playGameButton.mouseChildren = false;
Try e.currentTarget instead of e.target. From the documentation:
currentTarget : Object
[read-only] The object that is actively processing the Event object with an event listener.
target : Object
[read-only] The event target.
I'm not quite sure that this is your problem but the target vs currentTarget confusion has gotten me before.