我不斷收到以下錯誤,當我火射擊我在Flash CS6由AS 3.0拍攝閃光燈CS6的ActionScript子彈3.0
1118:靜態類型對象的值隱式強制爲可能無關的鍵入flash.display:DisplayObject。
package
{
import flash.display.MovieClip;
import flash.ui.Mouse;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.SoundChannel;
public class AvoiderGame extends MovieClip
{
public var army:Array;
public var reishoot:ReiShoot;
public var enemy:Enemy;
public var avatar:Avatar;
public var gameTimer:Timer;
public var useMouseControl:Boolean;
public var downKey:Boolean;
public var bullets:Array = [];
public var backgroundMusic:BackgroundMusic;
public var enemySound:EnemySound;
public var bgmSoundChannel:SoundChannel;
public var sfxSoundChannel:SoundChannel;
function AvoiderGame()
{
/*useMouseControl = false;
downKey = false;
if(useMouseControl)
{
avatar.x = mouseX;
avatar.y = mouseY;
}
else
{
avatar.x = 200;
avatar.y = 250;
}
*/
backgroundMusic = new BackgroundMusic();
bgmSoundChannel = backgroundMusic.play();
bgmSoundChannel.addEventListener(Event.SOUND_COMPLETE, onBackgroundMusicFinished);
enemySound = new EnemySound();
army = new Array();
//Initial Position of the Enemy
var newEnemy = new Enemy(2700, 600);
army.push(newEnemy);
addChild(newEnemy);
avatar = new Avatar();
addChild(avatar);
avatar.height = 220;
avatar.width = 120;
avatar.addEventListener(MouseEvent.CLICK, shoot);
gameTimer = new Timer(25);
gameTimer.addEventListener(TimerEvent.TIMER, onTick);
gameTimer.start();
//addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
}//End AvoiderGame
function shoot(e:MouseEvent):void
{
var b:Shot = new Shot();
b.addEventListener(Event.ENTER_FRAME, bulletflies);
stage.addChild(b);
bullets.push(b);
}
function bulletflies(e:Event):void
{
e.currentTarget.y -= 5;
if(e.currentTarget.y < 0 || e.currentTarget.y > stage.height)
{
stage.removeChild(e.currentTarget);
bullets.splice(bullets.indexOf(e.currentTarget), 1);
}
}
public function onBackgroundMusicFinished(event:Event):void
{
bgmSoundChannel = backgroundMusic.play();
bgmSoundChannel.addEventListener(Event.SOUND_COMPLETE, onBackgroundMusicFinished);
}
public function onKeyPress(keyboardEvent:KeyboardEvent):void
{
if (keyboardEvent.keyCode == Keyboard.DOWN)
{
downKey = true;
}
}
public function onKeyRelease(keyboardEvent:KeyboardEvent):void
{
if (keyboardEvent.keyCode == Keyboard.DOWN)
{
downKey = false;
}
}
public function onAddToStage(event:Event):void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPress);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyRelease);
}
public function onTick(timerEvent:TimerEvent):void
{
if (Math.random() < 2800)
{
var randomY:Number = Math.random() * 2800;
var newEnemy:Enemy = new Enemy(width, randomY);
army.push(newEnemy);
addChild(newEnemy);
gameScore.addToValue(1);
//sfxSoundChannel = enemySound.play();
}//End if statement
/*
if(useMouseControl)
{
avatar.x = mouseX;
avatar.y = mouseY;
}
else
{
if (downKey)
{
avatar.moveDown();
}
}
*/
avatar.x = mouseX;
avatar.y = mouseY;
for each (var enemy:Enemy in army)
{
enemy.moveDownABit();
if (avatar.hitTestObject(enemy))
{
bgmSoundChannel.stop();
gameTimer.stop();
dispatchEvent(new AvatarEvent(AvatarEvent.DEAD));
}//End if statement
}//End for loop
}//End onTick function
public function getFinalScore():Number
{
return gameScore.currentValue;
}
}//End AvoiderGame class
}//End package
您能否請您閱讀收到的錯誤中的行號,然後更新您的問題以僅包含相關代碼(即包含麻煩代碼的函數)。 – Marty
'Shot'類是否擴展MovieClip/Sprite? –
Shot擴展Sprite,並且錯誤位於第90行 – user3390593