package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
public class supportForce extends MovieClip
{
private var Player1Child:Player1Actual = new Player1Actual();
private var Player2Child:Player2Actual = new Player2Actual();
private var GreenLightLeft:Projectile1 = new Projectile1();
private var GreenLightRight:Projectile2 = new Projectile2();
private var _keyDownStatus:Object = {};
private var defaultSpeed:Number = 10;
private var Player1Lock:Boolean = false;
private var Player2Lock:Boolean = false;
private var Player1Left:Boolean = false;
private var Player2Left:Boolean = true;
private var greenLightLeft:Boolean = true;
private var Player1CD:Number = 0;
private var Player1Ready:Boolean = true;
private var Player1Hit:Boolean = false;
public function supportForce()
{
this.addEventListener(Event.ENTER_FRAME, general);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onUp);
stage.addEventListener(Event.ENTER_FRAME, keyCheck);
btnStart.addEventListener(MouseEvent.CLICK, clickStart);
btnAbout.addEventListener(MouseEvent.CLICK, clickAbout);
btnDust.addEventListener(MouseEvent.CLICK, clickDust);
}
private function general(event:Event)
{
if (Player1Child.BladeInstance.hitTestObject(Player2Child))
{
if (Player1Left == true)
{
Player2Child.x -= defaultSpeed;
}
if (Player1Left == false)
{
Player2Child.x += defaultSpeed;
}
}
if (Player1Ready == false)
{
Player1CD -= 1;
}
if (Player1CD <= 0)
{
Player1Ready = true;
}
if (Player1Child.x <= 0)
{
Player1Child.x = 0;
}
if (Player1Child.x >= 550)
{
Player1Child.x = 550;
}
if (Player1Child.y >= (400 - Player1Child.height))
{
Player1Child.y = 400 - Player1Child.height;
}
if (Player1Child.y <= 0)
{
Player1Child.y = 0;
}
if (Player2Child.x <= Player2Child.width)
{
Player2Child.x = Player2Child.width;
}
if (Player2Child.x >= 550)
{
Player2Child.x = 550;
}
if (Player2Child.y >= (400 - Player2Child.height))
{
Player2Child.y = 400 - Player2Child.height;
}
if (Player2Child.y <= 0)
{
Player2Child.y = 0;
}
}
private function onUp(e:KeyboardEvent):void
{
_keyDownStatus[e.keyCode] = false;
}
private function onDown(e:KeyboardEvent):void
{
_keyDownStatus[e.keyCode] = true;
}
private function keyCheck(event:Event)
{
if (_keyDownStatus[37])
{
if (Player1Left == false)
{
Player1Left = true;
Player1Child.rotation += 180;
Player1Child.y += (Player1Child.height - 5);
Player1Child.x += Player1Child.width;
}
Player1Child.x -= defaultSpeed;
}
if (_keyDownStatus[39])
{
if (Player1Left == true)
{
Player1Left = false;
Player1Child.rotation += 180;
Player1Child.y -= (Player1Child.height - 5);
Player1Child.x -= Player1Child.width;
}
Player1Child.x += defaultSpeed;
}
if (_keyDownStatus[38])
{
Player1Child.y -= defaultSpeed;
}
if (_keyDownStatus[40])
{
Player1Child.y += defaultSpeed;
}
if (_keyDownStatus[96] && Player1Ready == true)
{
Player1Ready = false;
Player1CD = 8;
Player1Child.play();
}
if (_keyDownStatus[65])
{
if (Player2Left == false)
{
Player2Left = true;
Player2Child.rotation -= 180;
Player2Child.y -= (Player2Child.height - 5);
Player2Child.x -= Player2Child.width;
}
Player2Child.x -= defaultSpeed;
}
if (_keyDownStatus[68])
{
if (Player2Left == true)
{
Player2Left = false;
Player2Child.rotation += 180;
Player2Child.y += (Player2Child.height - 5);
Player2Child.x += Player2Child.width;
}
Player2Child.x += defaultSpeed;
}
if (_keyDownStatus[87])
{
Player2Child.y -= defaultSpeed;
}
if (_keyDownStatus[83])
{
Player2Child.y += defaultSpeed;
}
if (_keyDownStatus[90])
{
if (Player2Left == true)
{
stage.addChild(GreenLightLeft);
GreenLightLeft.x = Player2Child.x;
GreenLightLeft.y = Player2Child.y;
greenLightLeft = true;
}
if (Player2Child == false)
{
stage.addChild(GreenLightRight);
GreenLightRight.x = (Player2Child.x - Player2Child.width);
GreenLightRight.y = (Player2Child.y - Player2Child.height);
greenLightLeft = false;
}
}
}
private function clickStart(event:MouseEvent):void
{
gotoAndStop(2);
}
private function clickAbout(event:MouseEvent):void
{
}
private function clickDust(event:MouseEvent):void
{
}
}
}
第一帧具有前奏像开始文件不能访问空对象引用的属性或方法,等和框架2具有MovieClip实例称为Player1Child和MovieClip内部是另一个名为BladeInstance的MovieClip。当我运行它时,它会在输出框中给出Error#1009,并且错误(我猜)是在“常规”函数中。 您可以下载.as文件的实际.fla文件,地址为https://www.mediafire.com/folder/i93zm31p7513m/A_Game。 如果可以的话,请为两个动画片段中的“转动”部分提供另一个更简单的方法(虽然它已经很好地工作了)。提前谢谢你。AS3 - 错误#1009:在supportForce /普通()
顺便说一下逻辑是我的哈哈。 :D – InfiniteParadox 2014-10-05 17:14:34