learning action script 3.0 from "http://www.lynda.com/ActionScript-3-tutorials/projects-game-development/366-2.html" and on its "chapter 1> winning a game" where score and damage to us is defined, i am getting errors of my movie clip.
Using three movie clips which i had to make and didn't download from their files: one is "cursor", one "monster" for which there is coding (look at bottom) and third is "mcEnergy" which is causing the problem (is a static class and shouldn't be or something (really new to flash programming)), it has three frames to show health at three stages.
so tell me how to fix this static class error, gona post the codes and errors below anyway if it helps.
Thanks in advance.
the three errors are
1119: Access of possibly undefined property totalFrames through a reference with static type Class.
Source: energy = mcEnergy.totalFrames;
1061: Call to a possibly undefined method gotoAndStop through a reference with static type Class.
mcEnergy.gotoAndStop(energy);
1061: Call to a possibly undefined method gotoAndStop through a reference with static type Class.
mcEnergy.gotoAndStop(energy);
Here is the main stage code
var monstersInGame:uint;
var monsterMaker:Timer;
var container_mc:MovieClip;
var cursor:MovieClip;
var score:int;
var energy:int;
function initializeGame():void
{
monstersInGame = 10;
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 = mcEnergy.totalFrames;
mcEnergy.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 Monster();
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("Winning!!!");
}
}
function decreaseEnergy():void
{
energy --;
if(energy <= 0)
{
monsterMaker.stop();
trace("You lose");
}
else
{
mcEnergy.gotoAndStop(energy);
}
}
initializeGame();
and here is for the monsters
import fl.motion.Animator;
import fl.motion.MotionEvent;
var this_xml:XML = <Motion duration="30" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="12" x="227.65" y="291.3" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="Monster">
<dimensions>
<geom:Rectangle left="-17.85" top="-17.85" width="35.7" height="35.7"/>
</dimensions>
<transformationPoint>
<geom:Point x="0.5" y="0.5"/>
</transformationPoint>
</Source>
</source>
<Keyframe index="0" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
</Keyframe>
<Keyframe index="29" scaleX="2.357" scaleY="2.357"/>
</Motion>;
var this_animator:Animator = new Animator(this_xml, this);
this_animator.play();
this_animator.addEventListener(MotionEvent.MOTION_END, hurtPlayer);
function hurtPlayer(Event:MotionEvent):void
{
var main:MovieClip = MovieClip(this.parent.parent);
main.decreaseEnergy();
this.parent.removeChild(this);
}
this.addEventListener(MouseEvent.CLICK, killMonster);
function killMonster(event:MouseEvent):void
{
this_xml = <Motion duration="5" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="12" x="236.95" y="163" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="Monster" class="Monster">
<dimensions>
<geom:Rectangle left="-17.85" top="-17.85" width="35.7" height="35.7"/>
</dimensions>
<transformationPoint>
<geom:Point x="0.5" y="0.5"/>
</transformationPoint>
</Source>
</source>
<Keyframe index="0" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
</Keyframe>
<Keyframe index="4" scaleX="0.552" scaleY="0.552">
<color>
<Color alphaMultiplier="0"/>
</color>
</Keyframe>
</Motion>;
this_animator = new Animator(this_xml, this);
this_animator.play();
this_animator.addEventListener(MotionEvent.MOTION_END, die);
}
function die(event:MotionEvent):void
{
var main:MovieClip = MovieClip(this.parent.parent);
main.increaseScore();
this_animator.removeEventListener(MotionEvent.MOTION_END, hurtPlayer);
this.parent.removeChild(this);
}