PDA

View Full Version : Any chance of someone helpin me with a problem with my pants shooting game?



Judda
May 8th, 2009, 07:28 PM
Cheers for taking time to look at this.
Im needing to get this little game finished in a week or so and having problems with a working energy bar which decreases when a bullys face gets to big before you shoot it. The energy bar is a simple movie tween consisting of 3 frames for the decreasing energy.

if I take out these parts of the code my game works ok:
var score:int;
var energy:int; (and all the sections which work with these :int; 's.)

This is posing a problem becuase I need an energy bar for the game to have a win lose ending.

HERE IS THE CODE

var monstersInGame:uint;
var monsterMaker:Timer;
var container_mc:MovieClip;
var cursor:MovieClip;
var score:int;
var energy:int;

function initializeGame(): void
{
monstersInGame = 15;
monsterMaker = new Timer (1000, monstersInGame);
container_mc = new MovieClip();
addChild(container_mc);

monsterMaker.addEventListener(TimerEvent.TIMER, createMonsters);
monsterMaker.start();

cursor = new Cursor();
addChild(cursor);
cursor.enabled = false
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCursor);

score = 0;
energy = energy_mc.totalFrames;
energy_mc.gotoAndStop(energy);
}

function dragCursor(event:MouseEvent):void
{
cursor.x = this.mouseX;
cursor.y = this.mouseY;
}

function createMonsters(event:TimerEvent):void
{
var monster:MovieClip;
monster = new bullyface();
monster.x = Math.random() * stage.stageWidth;
monster.y = Math.random() * stage.stageHeight;
container_mc.addChild(monster);
}

function increaseScore():void
{
score++;
if(score >= monstersInGame)
{
monsterMaker.stop();
trace("you beat that bully good!");
}
}

function decreseEnergy():void
{
energy --;
if(energy <=0)
{
monsterMaker.stop();
trace("you lose!")
}
else
{
energy_mc.gotoAndStop(energy);
}
}

initializeGame();


THESE ARE THE ERRORS

Scene1: Layer'Actions' Frame1, Line25 - 1120: Access of undefined property energy_mc. energy = energy_mc.totalFrames;
Scene1: Layer'Actions' Frame1, Line 26 - 1120: Access of undefined property energy_mc. energy_mc.gotoAndStop(energy);
Scene1: Layer'Actions' Frame1, Line 64 - 1120: Access of undefined property energy_mc. energy_mc.gotoAndStop(energy);

I appreciate any help with this matter, Thanks again for taking time to look over this.

Leon

belegdae
May 10th, 2009, 12:14 PM
pretty sure it's this line thats broken

energy = energy_mc.totalFrames;

maybe just define it as

energy = 3

if your energy MC only has 3 frames?

Judda
May 11th, 2009, 06:33 PM
I'll give it a try. Thanks for the reply.

Leon

Judda
May 11th, 2009, 06:40 PM
So i've just try'd replacing energy = energy_mc.totalFrames; with energy = 3;...... but it hasn't changed anything. Poo......, what to do?

Daganev
May 11th, 2009, 07:15 PM
Does the movieclip with the instance name of energy_mc exist on the first frame in the timeline?

Judda
May 18th, 2009, 11:07 PM
Rookie mistake,...... I stupidly gave it an instance name of Energy_mc not energy_mc........ What a school boy error. Cheers for the help everyone