如果有人可以帮助或给我一些指导来解决这些错误,请给我任何提示,或者建议一个更好的方法来学习AS3我会非常感激。
我有一个主要的AS3文件:(我将所有导入都放在不同的行上但由于某种原因,该网站将它们全部放在一行中。)
主要课程:
package
{
import flash.display.MovieClip
import flash.events.Event
import flash.events.KeyboardEvent
public class DocumentMainNew extends MovieClip
{
public function DocumentMainNew():void
{
var angela:Hero = new Hero();
var worm1:Enemy = new Enemy();
angela.health = 100;
angela.mana = 100;
stage.focus = stage;
}
}
}
英雄课程:
package
{
import flash.events.Event;
import flash.events.KeyboardEvent
import flash.display.MovieClip;
import flash.geom.Point;
public class Hero extends MovieClip
{
//Objects
public var angela:Hero;
public var startMarker:StartMarker;
public var boundaries:Boundaries;
public var up:Up;
public var powerUp:PowerUp;
public var enemy:Enemy;
//Regular vars
public var health:Number;
public var mana:Number
private var vx:Number;
private var vy:Number;
private var jumps:Number;
private var allowJump:Boolean;
private var collision:Boolean;
public function Hero()
{
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
up.visible = false;
startMarker.visible = false;
}
public function enterFrameHandler(e:Event):void
{
//Gravitates the player
vy += 2;
//Moves the player
angela.x += vx;
angela.y += vy;
//processes collisions
processCollisions();
//scrolls the stage
scrollStage();
}
public function keyDownHandler(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case 37: //left arrow
vx = -7;
break;
case 39: //right arrow
vx = 7;
break;
case 38: //up arrow
if(jumps < 1)
{
if(allowJump)
{
vy = -20;
jumps++;
}
}
break;
default:
}
}
public function keyUpHandler(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case 37:
vx = 0;
break;
case 39:
vx = 0;
break;
case 38:
break;
default:
break;
}
}
public function processCollisions():void
{
//detects when player is falling
if(vy > 0)
{
//respawns the player if they fell of the stage
if(angela.y > stage.stageHeight)
{
angela.x = startMarker.x;
angela.y = startMarker.y;
boundaries.x = 0;
boundaries.y = 0;
vy = 0;
jumps = 0;
}
//otherwise, processes collisions with boundaries
else
{
collision = false;
if(boundaries.hitTestPoint(angela.x, angela.y, true))
{
collision = true;
allowJump = true;
jumps = 0;
}
if (collision)
{
while (collision)
{
angela.y -= 0.1;
collision = false;
}
if(boundaries.hitTestPoint(angela.x,angela.y,true))
{
collision = true;
}
vy = 0;
}
}
}
}
public function scrollStage():void
{
boundaries.x += (stage.stageWidth * 0.5) - angela.x;
angela.x = stage.stageWidth * 0.5;
enemy.x = boundaries.x + 30;
powerUp.x = boundaries.x - 200;
}
}
}
我收到这些错误:(无法输入错误,因为某些原因会将帖子标记为格式不正确) Errors 感谢您的任何帮助。我真的很抱歉,如果这是一个糟糕的问题,我已经尝试找到这个问题的答案,但无法解决任何问题或找到我应该如何使用类的任何解释。
答案 0 :(得分:0)
启用调试(菜单文件 - &gt;发布设置 - &gt; SWF - &gt;允许调试)以了解给您带来麻烦的确切行。
然后,我很确定在 Hero 构造函数中无法访问阶段,因为阶段仅适用于附加的对象到显示列表。你需要:
我认为这会奏效。主要课程:
expensive simulation
英雄课程:
var angela:Hero = new Hero;
addChild(angela);