从“ http://www.lynda.com/ActionScript-3-tutorials/projects-game-development/366-2.html ”学习动作脚本3.0及其“第1章>赢得比赛”,其中得分和伤害我们已定义,我的电影剪辑出现错误。
使用我必须制作并且没有从他们的文件中下载的三个电影剪辑:一个是“光标”,一个是有编码的“怪物”(看底部),第三个是导致问题的“mcEnergy”(是一个静态类,不应该是什么(对闪存编程来说真的很新)),它有三个帧来显示三个阶段的健康状况。
所以告诉我如何修复这个静态类错误,如果有帮助的话,无论如何都要在下面发布代码和错误。
提前致谢。
这三个错误是
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);
这是主要阶段代码
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();
这是给怪物的
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);
}