2013-06-06 71 views
-2

我在這一個錯誤的重大問題1046 AS3編譯錯誤

//Obligitory Stop 
stop(); 

//Imports 
import flash.events.Event; 
import flash.events.KeyboardEvent; 
import fl.motion.easing.Back; 
import flash.events.MouseEvent; 
import flash.accessibility.Accessibility; 
import flash.utils.Timer; 
import flash.events.TimerEvent; 
import flash.display.MovieClip; 


//Variables 
var bulletSpeed:uint = 20; 
var scoreData:int; 
var bullets:Array = new Array(); 
var killCounter:int; 
var baddieCounter:int; 
var currentLevel:int = 1; 
var baddieDamage:int; 
var energyCost:int; 
var target:MovieClip; 
var baddies:Array = new Array(); 
var timer:Timer = new Timer(1); 
var baddieSpeed:int; 
var score:int; 
var levelKR:int; 
var level1KR:int = 10; 
var level2KR:int = 25; 
var level3KR:int = 50; 
var upPressed:Boolean = false; 
var downPressed:Boolean = false; 
var Baddie:MovieClip 
var mySound:Sound = new ShootSFX(); 

//Level Atributes set 
if (currentLevel == 1) 
{ 
    baddieSpeed = 2; 
    baddieDamage = 20; 
    timer.delay = 4000; 
    levelKR = level1KR; 
    bulletSpeed = 10; 
    energyCost = 50; 
    var energyTimer:Timer = new Timer(50); 
    var healthTimer:Timer = new Timer(1000); 
} 

//Event Listeners 
stage.addEventListener(MouseEvent.MOUSE_DOWN, fireGun); 
stage.addEventListener(Event.ENTER_FRAME, moveObjects); 
timer.addEventListener(TimerEvent.TIMER, addBaddie); 
rbDash.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey); 
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed); 
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed); 

//Timers Start 
timer.start(); 
energyTimer.start(); 
healthTimer.start(); 

//Initialize score 
Score.text = String("Level "+currentLevel+" - begin!"); 

//load score data 
score = scoreData; 

//Checks Kill Counter 
checkKillCounter(); 


//Shoot gun on space 
function fireGun(evt:KeyboardEvent) 
{ 
    if (evt.keyCode == Keyboard.SPACE) 
    { 
     bullet.x = rbDash.x; 
     bullet.y = rbDash.y + 50; 
     addChild(bullet); 
     bullets.push(bullet); 

    } 

} 

//Move Objects 
function moveObjects(evt:Event):void 
{ 
    moveBullets(); 
    moveBaddies(); 
} 

//Move bullets 
function moveBullets():void 
{ 
    for (var i:int = 0; i < bullets.length; i++) 
    { 
     var dx = Math.cos(deg2rad(bullets[i].rotation)) * bulletSpeed; 
     var dy = Math.sin(deg2rad(bullets[i].rotation)) * bulletSpeed; 
     bullets[i].x += dx; 
     bullets[i].y += dy; 
     if (bullets[i].x <-bullets[i].width 
     || bullets[i].x > stage.stageWidth + bullets[i].width 
     || bullets[i].y < -bullets[i].width 
     || bullets[i].y > stage.stageHeight + bullets[i].width) 
     { 
      removeChild(bullets[i]); 
      bullets.splice(i, 1); 
     } 
    } 
} 

//Spawns Enemy 
function addBaddie(evt:TimerEvent):void 
{ 
    updateScore(25); 
    var baddie:Baddie = new Baddie(); 
    var side:Number = Math.ceil(Math.random() * 4); 
    if (side == 1) 
    { 
     baddie.x = Math.random() * stage.stageWidth; 
     baddie.y = - baddie.height; 
    } 
    else if (side == 2) 
    { 
     baddie.x = stage.stageWidth + baddie.width; 
     baddie.y = Math.random() * stage.stageHeight; 
    } 
    else if (side == 3) 
    { 
     baddie.x = Math.random() * stage.stageWidth; 
     baddie.y = stage.stageHeight + baddie.height; 
    } 
    else if (side == 4) 
    { 
     baddie.x = - baddie.width; 
     baddie.y = Math.random() * stage.stageHeight; 
    } 
    baddie.speed = baddieSpeed; 
    addChild(baddie); 
    baddies.push(baddie); 
    baddieCounter += 1; 
    if (baddieCounter == levelKR) 
    { 
     timer.stop(); 
    } 
} 

//Moves Enemy 
function moveBaddies():void 
{ 
    for (var i:int = 0; i < baddies.length; i++) 
    { 
     var dx = Math.cos(deg2rad(baddies[i].angle)) * baddies[i].speed; 
     var dy = Math.sin(deg2rad(baddies[i].angle)) * baddies[i].speed; 
     baddies[i].x += dx; 
     baddies[i].y += dy; 
     if (baddies[i].hitTestPoint(rbDash.x,rbDash.y,true)) 
     { 
      removeChild(baddies[i]); 
      baddies.splice(i, 1); 
      //HealthBar.gotoAndStop(HealthBar.currentFrame + baddieDamage); 
      killCounter += 1; 
      checkKillCounter(); 
      //if (HealthBar.currentFrame == 100) 
      { 
       gotoAndStop(5); 
      } 
     } 
     else 
     { 
      checkForHit(baddies[i]); 
     } 
    } 
} 


//Hit detection 
function checkForHit(baddie:Baddie):void {//Level 1, Layer 'Actions', Frame 1, Line 166 1046: Type was not found or was not a compile-time constant: Baddie. 
    for (var i:int = 0; i < bullets.length; i++) 
    { 
     if (baddie.hitTestPoint(bullets[i].x,bullets[i].y,true)) 
     { 
      removeChild(baddie); 
      removeChild(bullets[i]); 
      baddies.splice(baddie.indexOf(baddie), 1); 
      bullets.splice(bullets[i]); 
      updateScore(100); 
      killCounter += 1; 
      checkKillCounter(); 
     } 
    } 
} 

//Updates score 
function updateScore(points:int):void 
{ 
    score += points; 
    Score.text = String("Points: "+score); 
} 

//stops timers 
function timerStop():void 
{ 
    timer.stop(); 
    energyTimer.stop(); 
    healthTimer.stop(); 
} 

//Y axis movement 
//totaly not a code snippet 
function fl_MoveInDirectionOfKey(event:Event) 
{ 
    if (upPressed) 
    { 
     rbDash.y -= 5; 
    } 
    if (downPressed) 
    { 
     rbDash.y += 5; 
    } 
} 

function fl_SetKeyPressed(event:KeyboardEvent):void 
{ 
    switch (event.keyCode) 
    { 
     case Keyboard.UP : 
      { 
       upPressed = true; 
       break; 

      }; 
     case Keyboard.DOWN : 
      { 
       downPressed = true; 
       break; 

     } 
    } 
}; 

function fl_UnsetKeyPressed(event:KeyboardEvent):void 
{ 
    switch (event.keyCode) 
    { 
     case Keyboard.UP : 
      { 
       upPressed = false; 
       break; 

      }; 
     case Keyboard.DOWN : 
      { 
       downPressed = false; 
       break; 

     } 

    } 
}; 

//makes the deg2rad work for the bullets/enemy 
function deg2rad(degree) 
{ 
    return degree * (Math.PI/180);//Had issues with "deg2rad" functions 
} 

//Removes listeners 
function removeAllListeners():void 
{ 
    stage.removeEventListener(MouseEvent.MOUSE_DOWN, fireGun); 
    stage.removeEventListener(Event.ENTER_FRAME, moveObjects); 
    timer.removeEventListener(TimerEvent.TIMER, addBaddie); 
} 

//Checks if level end 
function checkKillCounter():void 
{ 
    EnemiesLeft.text = ("Enemies Left: "+String(levelKR - killCounter)); 
    if (killCounter == levelKR) 
    { 
     shutdown(); 
     gotoAndStop(3); 
    } 
} 

//Stops everything 
function shutdown():void 
{ 
    timerStop(); 
    removeAllListeners(); 
    removeChild(target); 
} 

我得到1級,層「操作」,第1幀,166線1046:類型未找到或不是一個編譯時常量:Baddie。

謝謝你們 我試着今天完成這個工作,所以我可以在

回答

1

Baddie移動一類就是在默認的包?如果沒有,你需要導入它:

import packagename.Baddie; 

如果Baddie是一個庫符號,請確保您選中了「爲ActionScript導出」和鏈接名稱是否正確。還要確保是在第1幀中導出,或者至少在代碼所在的幀之前或之後導出。

+0

它不是一個包,它是一個電影剪輯 – wizardmorax

+0

@wizardmorax我明白了,所以你的意思是'Baddie'是一個圖書館符號? – Marty

0

在你的圖書館中,右鍵點擊Baddie並選擇「屬性」並選中「導出爲ActionScript」。現在,您可以使用Baddie作爲擴展MovieClip的類。

對不起,我沒有注意到這已被推薦。基本上,您的錯誤找不到名爲Baddie的Class,因此您需要通過Library實例指定自定義類。