Accessing the .name property in a click handler - actionscript-3

I am trying to make a simple card matching game via flash + actionscript, and am having major trouble with assigning event listeners and name. I have got all the card generation statements in place, and they all draw onto my stage, but even though I assigning their instance name with newCard.name, the name I get when tracing the click is always "root1" on every single button, and I have no idea why.
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public dynamic class cardGameMain extends MovieClip {
public function cardGameMain() {
addCards();
}
public function addCards() {
var lastCard:int;
for (var i = 1; i < 17; i++) {
var newCard:MovieClip;
newCard = new cardBackSymbol();
newCard.name = "card" + i;
addChild(newCard);
newCard.addEventListener(MouseEvent.MOUSE_UP, decideCard);
if (i == 1 || i == 5 || i == 9 || i == 13) {
newCard.x = 20;
if (i == 1) {
newCard.y = 20;
}
else if (i == 5) {
newCard.y = 240;
}
else if (i == 9) {
newCard.y = 460;
}
else if (i == 13) {
newCard.y = 680;
}
lastCard = 20;
} else if (i > 1 && i < 5) {
newCard.x = lastCard + 145;
newCard.y = 20;
lastCard = lastCard + 145;
} else if (i > 5 && i < 9) {
newCard.x = lastCard + 145;
newCard.y = 240;
lastCard = lastCard + 145;
} else if (i > 9 && i < 13) {
newCard.x = lastCard + 145;
newCard.y = 460;
lastCard = lastCard + 145;
} else {
newCard.x = lastCard + 145;
newCard.y = 680;
lastCard = lastCard + 145;
}
trace(newCard.name + " position is " + newCard.x + ", " + newCard.y);
}
}
public function decideCard(e:MouseEvent):void {
trace(this.name)
}
}
}
Any help on the matter is MUCH appretiated!

You're using the this keyword which is referring to the containing class, not the object clicked.
Try this instead:
public function decideCard(e:MouseEvent):void {
trace(DisplayObject(e.currentTarget).name)
}

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

Why my app is different when i publish it and run it on android device?

I build a platform game using adobe cs5.5 and written with as3.
When i test my app on pc the game is running perfect but when i
publish it and run it to my android device i have some gravity issues.
Sometimes when i land on ground all the stage start to tremble.
The strange is, in the same level in the same ground sometimes the stage start
tremble and sometimes not.
Is that a problem in my code or something else?
I use 800w x 480h stage.
i publish using GPU mode.
All my ground inside i draw it with shape.
var xvel = 0;
var yvel = 0;
var GRA = 1;
var FRICT = 0.85;
var downarr = new Array(-12,0,12);
var vertarr = new Array(-20,-30);
var uparr = new Array(-3,0,3);
this.addEventListener(Event.ENTER_FRAME,FramesEvents);
function windowcamera()
{
var newx = - savvito.x + 350;
var distx = newx - bg.x;
bg.x += distx;
var newy = - savvito.y + 370;
var disty = newy - bg.y;
bg.y += disty;
}
function phys()
{
savvito.x += xvel;
savvito.y += yvel;
xvel *= FRICT;
yvel += GRA;
if (yvel > 8)
{
yvel = 8;
}
if (yvel > 2)
{
onground = false;
}
savvito.virtx = savvito.x + bg.x;
savvito.virty = savvito.y + bg.y;
downPush(savvito);
leftPush(savvito);
rightPush(savvito);
upPushCloud(savvito);
upPush(savvito);
}
function runJump()
{
onground = false;
yvel = - 12;
}
function downPush(d)
{
d.virtx = d.x + bg.x;
d.virty = d.y + bg.y;
for (var i = 0; i < uparr.length; i++)
{
var num = uparr[i];
var tx = d.virtx + num;
var ty = d.virty - 40;
while (bg.ground.hitTestPoint(tx , ty , true))
{
d.virty++;
ty++;
d.y++;
yvel = 1;
}
for (var ie=0; ie<boxingArr.length; ie++)
{
var e = boxingArr[ie];
if (e.liftthisbox == 0)
{
while (e.hitTestPoint(tx , ty , true))
{
e.y--;
e.yvel = 0;
}
}
}
}
}
function rightPush(d)
{
d.virtx = d.x + bg.x + xvel;
d.virty = d.y + bg.y;
for (var i = 0; i < vertarr.length; i++)
{
var num = vertarr[i];
var tx = d.virtx + 15;
var ty = d.virty + num;
while (bg.ground.hitTestPoint(tx , ty , true))
{
d.virtx--;
tx--;
d.x--;
xvel = 0;
}
for (var ie=0; ie<boxingArr.length; ie++)
{
var e = boxingArr[ie];
if (e.liftthisbox == 0)
{
while (e.hitTestPoint(tx , ty , true))
{
d.virtx--;
tx--;
d.x--;
xvel = 0;
}
}
}
}
}
function leftPush(d)
{
d.virtx = d.x + bg.x + xvel;
d.virty = d.y + bg.y;
for (var i = 0; i < vertarr.length; i++)
{
var num = vertarr[i];
var tx = d.virtx - 15;
var ty = d.virty + num;
while (bg.ground.hitTestPoint(tx , ty , true))
{
d.virtx++;
tx++;
d.x++;
xvel = 0;
}
for (var ie=0; ie<boxingArr.length; ie++)
{
var e = boxingArr[ie];
if (e.liftthisbox == 0)
{
while (e.hitTestPoint(tx , ty , true))
{
d.virtx++;
tx++;
d.x++;
xvel = 0;
}
}
}
}
}
function upPushCloud(d)
{
if (yvel > 0)
{
d.virtx = d.x + bg.x;
d.virty = d.y + bg.y;
for (var i = 0; i < downarr.length; i++)
{
var num = downarr[i];
var tx = d.virtx + num;
var ty = d.virty;
while (bg.cloudbg.hitTestPoint(tx , ty , true))
{
onground = true;
jdown = false;
d.virty--;
ty--;
d.y--;
yvel = 0;
}
}
}
}
function upPush(d)
{
d.virtx = d.x + bg.x;
d.virty = d.y + bg.y;
for (var i = 0; i < downarr.length; i++)
{
var num = downarr[i];
var tx = d.virtx + num;
var ty = d.virty;
while (bg.ground.hitTestPoint(tx , ty , true))
{
onground = true;
jdown = false;
d.virty--;
ty--;
d.y--;
yvel = 0;
}
for (var ie=0; ie<boxingArr.length; ie++)
{
var e = boxingArr[ie];
while (e.hitTestPoint(tx , ty , true))
{
onground = true;
jdown = false;
d.virty--;
ty--;
d.y--;
yvel = 0;
}
}
}
}
function FramesEvents(e:Event)
{
phys();
controls();
windowcamera();
}

Got lost on this code and cant make it work

Im getting an weird error about constructions definitions that i have no idea what means.
Im studing this for a test.I think the problem is on the functions but im not sure.
Its a code from an game (pretty simple one) that you have to move your player from point b to point a without letting the falling asteroids touch you.
Thanks in advance.
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
var up:Boolean;
var down:Boolean;
var left:Boolean;
var right:Boolean;
var vel:Number;
var velInimigo:Number;
var sentidoX:Number;
var sentidoY:Number;
var d:MovieClip;
var txt1:MovieClip;
var chegada:MovieClip;
var player:MovieClip;
var inimigos:Array;
var i:int;
var mc:MovieClip;
function MainTimeline()
{
addFrameScript(0, frame1);
return;
}
function OnKeyDown(event:KeyboardEvent) : void
{
switch(event.keyCode)
{
case Keyboard.W:
{
up = true;
break;
}
case Keyboard.S:
{
down = true;
break;
}
case Keyboard.A:
{
left = true;
break;
}
case Keyboard.D:
{
right = true;
break;
}
default:
{
break;
}
}
return;
}
function OnKeyUp(event:KeyboardEvent) : void
{
switch(event.keyCode)
{
case Keyboard.W:
{
up = false;
break;
}
case Keyboard.S:
{
down = false;
break;
}
case Keyboard.A:
{
left = false;
break;
}
case Keyboard.D:
{
right = false;
break;
}
default:
{
break;
}
}
return;
}
function OnFrame(event:Event) : void
{
var loc3: = null;
var loc4: = null;
if (up)
{
sentidoY = -1;
}
else if (down)
{
sentidoY = 1;
}
else
{
sentidoY = 0;
}
if (left)
{
sentidoX = -1;
}
else if (right)
{
sentidoX = 1;
}
else
{
sentidoX = 0;
}
if (sentidoX == 1 && sentidoY == 0)
{
player.rotation = 0 + 90;
}
else if (sentidoX == 1 && sentidoY == 1)
{
player.rotation = 45 + 90;
}
else if (sentidoX == 0 && sentidoY == 1)
{
player.rotation = 90 + 90;
}
else if (sentidoX == -1 && sentidoY == 1)
{
player.rotation = 135 + 90;
}
else if (sentidoX == -1 && sentidoY == 0)
{
player.rotation = 180 + 90;
}
else if (sentidoX == -1 && sentidoY == -1)
{
player.rotation = 225 + 90;
}
else if (sentidoX == 0 && sentidoY == -1)
{
player.rotation = 270 + 90;
}
else if (sentidoX == 1 && sentidoY == -1)
{
player.rotation = 315 + 90;
}
player.x = player.x + vel * sentidoX;
player.y = player.y + vel * sentidoY;
var loc2: = 0 ;
while (loc2 < inimigos.length)
{
loc3 = inimigos[loc2];
loc3.y = loc3.y + loc3.vel;
loc3.rotation = loc3.rotation + loc3.rotVel;
if (loc3.hitTestObject(player))
{
loc4 = new GameOverMC();
stage.addChild(loc4);
loc4.x = stage.stage.width / 2;
loc4.y = stage.stageHeight / 2;
stage.removeEventListener(Event.ENTERFRAME, OnFrame);
}
if (loc3.y > stage.stageHeight)
{
loc3.y = -loc3.height;
}
loc2++;
}
if (player.hitTestObject(chegada))
{
if (txt1 == null)
{
txt1 = new VitoriaMC();
stage.addChild(txt1);
txt1.x = stage.stage.width / 2;
txt1.y = stage.stageHeight / 2;
}
}
d.x = d.x + d.vel * d.sx;
d.y = d.y + d.vel * d.sy;
if (d.x >= stage.stageWidth - d.width / 2 || d.x <= d.width / 2)
{
d.sx = -d.sx;
}
if (d.y >= stage.stageHeight - d.height / 2 || d.y <= d.height / 2)
{
d.sy = -d.sy;
}
return;
}
function frame1()
{
vel = 5;
velInimigo = 2;
sentidoX = 0;
sentidoY = 0;
d = new DemoMC();
d.vel = 1;
d.sx = 1;
d.sy = 1;
d.x = stage.stageWidth / 2;
d.y = stage.stageHeight / 2;
txt1 = null;
chegada = new ChegadaMC();
player = new PlayerMC();
inimigos = new Array();
stage.addChild(d);
stage.addChild(chegada);
stage.addChild(player);
player.x = player.width / 2;
player.y = stage.stageHeight - player.height / 2;
chegada.x = stage.stageWidth - chegada.width;
chegada.y = 0;
i = 0;
while (i < 60)
{
mc = new AstroMC();
stage.addChild(mc);
inimigos.push(mc);
mc.x = 100 + Math.random() * (600 - mc.width);
mc.y = Math.random() * stage.stageHeight;
mc.rotVel = Math.random() * 10 - 5;
mc.vel = Math.random() * 3 + 1;
var loc1: = i;
var loc2: = i + 1;
loc1.i = loc2;
}
stage.addEventListener(KeyboardEvent.KEYDOWN, OnKeyDown);
stage.addEventListener(KeyboardEvent.KEYUP, OnKeyUp);
stage.addEventListener(Event.ENTERFRAME, OnFrame);
return;
}
It has been awhile since i have played with AS3 but i see a few odd things one being the
loc1.i = loc2;
near the bottom
what is "i" in relation to loc1? and this is in a while loop using i but never increments it so it seems like an infinite loop
again i could be wrong its been quite some time.

Creating variable names

I'm having trouble with the following function:
private function whichLevelToLoad():void{
if(levelToLoad == "nothing"){
currentLevel = null;
}
var thisObj:Object = new Object();
if(levelBtnArray!=null){
for(var j:int=levelBtnArray.length-1;j>=0;j--) {
if(levelToLoad == String("level " + (j+1))){
thisObj["level"+(j+1)] = new ["Level"+(j+1)]();--------------------------->The Problem
thisObj["level" + (j+1)].x = 0;
thisObj["level" + (j+1)].y = 0;
addChildAt(thisObj["level" + (j+1)], 0);
currentLevel = thisObj["level" + (j+1)];
}
}
}
}
I'm trying to instatiate 75 objects by using a loop. The line would look like this,"thisObj.level1 = new Level1(); with the numbers going from 1-75. Is this possible? How
do I do it?
Try
if(levelBtnArray!=null){
var levelClass:Class;
for(var j:int=levelBtnArray.length-1;j>=0;j--) {
if(levelToLoad == String("level " + (j+1))){
levelClass = getDefinitionByName( "Level"+(j+1) ) as Class;
thisObj["level"+(j+1)] = new levelClass();
thisObj["level" + (j+1)].x = 0;
thisObj["level" + (j+1)].y = 0;
addChildAt(thisObj["level" + (j+1)], 0);
currentLevel = thisObj["level" + (j+1)];
}
}
}

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);
}