我有一個煩人的問題。我搜索了一下,找不到任何好的答案,所以我希望能在這裏找到一些幫助。「上傳」不是函數
我得到這個錯誤,這似乎是相當普遍:definently
TypeError: Error #1006: update är inte en funktion. // = update is not a function (english)
at se.qmd.spaceInvaders::ShipHandler/onEnterFrame()
更新是一個函數,所以我真的不明白是什麼問題。
我的設置。我正在使用Flashdevelop。我有一個主類,它被設置爲我的fla文件中的文檔類。 我在se.qmd.spaceInvaders和se.qmd.starLight我在SRC文件夾主類,和我的子類的封裝結構。我還使用TweenMax並將其保存在src文件夾的「正常」包裝結構中。
在主I類添加到舞臺的實例類LeGun的 - 這也是在FLA文件的「輸出」影片剪輯,該類StarHandler的實例和類ShipHandler的一個實例。我還有一個鍵盤監聽器,它在enterframe函數的幫助下移動我的LeGun類的實例。 好,沒問題。 StarHandler的工作方式應該是這樣,ShipHandler的工作方式應該如此,直到我在Ship類中調用1或2種方法 - 這也是fla文件中的「導出」動畫片段。 Ship類當然是包含由ShipHandler處理的Ship的類。
我在下面包括我的ShipHandler和Ship類,並希望它不會讓這個帖子超過一定的長度。 ShipHandler.as:
package se.qmd.spaceInvaders {
import flash.display.MovieClip;
import se.qmd.spaceInvaders.Ship;
import flash.display.Stage;
import flash.events.Event;
public class ShipHandler extends MovieClip {
private var _shipArray:Array = [];
private const NUM_START_SHIPS:int = 25;
private var s:Stage = null;
private var _directionX:Number = 1;
private var _directionY:Number = 1;
private var _velocityX:Number;
private var _velocityY:Number;
private const YBORDER_TOP:int = 50;
private const YBORDER_BOTTOM:int = 525;
public function ShipHandler(o:Stage) {
s = o; // tar emot stage från main
createObjects();
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function createObjects():void {
for (var i:int = 0; i < NUM_START_SHIPS; i++) {
var aShip:Ship = new Ship();
aShip.x = Math.random() * (s.stageWidth - aShip.width) + aShip.width/2;
aShip.y = Math.random() * (s.stageHeight - aShip.height -135) + aShip.height/2 + 55;
this.addChild(aShip);
_shipArray.push(aShip);
aShip.startMove(Math.random(), Math.random());
}
}
private function onEnterFrame(e:Event):void {
for (var i:int = 0; i < _shipArray.length; i++) {
var aShip:Ship = _shipArray[i] as Ship;
aShip.update();
}
}
}
}
Ship.as:
package se.qmd.spaceInvaders {
import flash.display.MovieClip;
import flash.events.Event;
public class Ship extends MovieClip {
private var _directionX:Number = 1;
private var _directionY:Number = 1;
private var _velocityX:Number;
private var _velocityY:Number;
private const YBORDER_TOP:int = 50;
private const YBORDER_BOTTOM:int = 525;
public function Ship() {
//s = o; // tar emot stage
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
this.width = 50;
this.height = 18;
}
public function update():void {
// x led vänster kant
if(this.x <= this.width/2) {
this.x = this.width/2;
_directionX *= -1;
}
// x led höger kant
if(this.x >= 800 - this.width/2) {
this.x = 800 - this.width/2;
_directionX *= -1;
}
// y led top kant
if(this.y <= YBORDER_TOP + this.height/2) {
this.y = YBORDER_TOP + this.height/2;
_directionY *= -1;
}
// y led botten kant
if(this.y >= YBORDER_BOTTOM - this.height/2) {
this.y = YBORDER_BOTTOM - this.height/2;
_directionY *= -1;
}
this.x += _velocityX * _directionX;
this.y += _velocityY * _directionY;
}
public function startMove(directionX:Number, directionY:Number):void {
trace(directionX, directionY);
_velocityX = 10;
_velocityY = 10;
if (directionX < 0.5) {
_directionX = -1;
}
if (directionY < 0.5) {
_directionY = -1;
}
}
public function changeDirection():void {
_directionX *= -1;
_directionY *= -1;
}
}
}
,只要我調用其中的方法startMove或更新從ShipHandler,我得到我上面寫的錯誤。 將不勝感激任何幫助,因爲在我看來,我必須做一些根本性的錯誤...
獲取相同的錯誤,如果我嘗試你的第一個例子:( 不知道如何使用矢量,但我在我的StarHandler類以非常類似的方式使用數組,並且它在那裏工作.. 。 – Poppe76 2010-12-09 13:19:53
當你使用我的代碼時,你會得到同樣的錯誤,還是你得到自定義錯誤(ship位置爲空)? – Mattias 2010-12-09 14:02:42