私のコードの何が問題なのかわかりません。助けてください。
エラー:
シーン 1、レイヤー「アクション」、フレーム 3、120 行目 1180: 未定義の可能性があるメソッド rad2deg を呼び出します。シーン 1、レイヤー「アクション」、フレーム 3、121 行目 1180: 未定義の可能性があるメソッド rad2deg を呼び出します。シーン 1、レイヤー「アクション」、フレーム 3、129 行目 1180: 未定義の可能性があるメソッド rad2deg を呼び出します。
コード:
import flash.utils.Timer;
import flash.events.TimerEvent;
var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
var missile:Array = new Array();
var timer: Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, addMissile);
timer.start();
plane.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_2);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_2);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_2);
stage.addEventListener(Event.ENTER_FRAME, moveObjects);
function fl_MoveInDirectionOfKey_2(event:Event)
{
if (upPressed)
{
plane.y -= 8;
}
if (downPressed)
{
plane.y += 8;
}
if (leftPressed)
{
plane.x -= 8;
}
if (rightPressed)
{
plane.x += 8;
}
}
function fl_SetKeyPressed_2(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = true;
break;
}
case Keyboard.DOWN:
{
downPressed = true;
break;
}
case Keyboard.LEFT:
{
leftPressed = true;
break;
}
case Keyboard.RIGHT:
{
rightPressed = true;
break;
}
}
}
function fl_UnsetKeyPressed_2(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = false;
break;
}
case Keyboard.DOWN:
{
downPressed = false;
break;
}
case Keyboard.LEFT:
{
leftPressed = false;
break;
}
case Keyboard.RIGHT:
{
rightPressed = false;
break;
}
}
}
function addMissile(evt:TimerEvent):void {
var missile:Missile = new Missile();
var side:Number = Math.ceil(Math.random() * 4);
if (side == 1) {
missile.x = Math.random() * stage.stageWidth;
missile.y = - missile.height;
} else if (side == 2) {
missile.x = stage.stageWidth + missile.width;
missile.y = Math.random() * stage.stageHeight;
} else if (side == 3) {
missile.x = Math.random() * stage.stageWidth;
missile.y = stage.stageHeight + missile.height;
} else if (side == 4) {
missile.x = - missile.width
missile.y = Math.random() * stage.stageHeight;
}
missile.angle = getAngle(missile.x, missile.y, plane.x, plane.y);
missile.speed = Math.ceil(Math.random() * 15);
addChild(missile);
missile.push(missile);
}
function moveObjects(evt:Event):void {
moveMissile();
}
function moveMissile():void {
for (var i:int = 0; i < missile.length; i++) {
var dx = Math.cos(rad2deg(missile[i].angle)) * missile[i].speed;
var dy = Math.sin(rad2deg(missile[i].angle)) * missile[i].speed;
missile[i].x += dx;
missile[i].y += dy;
}
}
function getAngle(x1:Number, y1:Number, x2:Number, y2:Number):Number {
var radians:Number = Math.atan2(y2 - y1, x2 - x1);
return rad2deg(radians);
}