【发布时间】:2010-12-10 17:19:04
【问题描述】:
我有一个烦人的问题。我google了一下,并没有真正找到任何好的答案,所以我希望在这里找到一些帮助。
我遇到了这个错误,这似乎很常见:
TypeError: Error #1006: update är inte en funktion. // = update is not a function (english)
at se.qmd.spaceInvaders::ShipHandler/onEnterFrame()
updatedefinently是一个函数,所以我真的不明白问题出在哪里。
我的设置。我正在使用 Flashdevelop。我有一个 Main 类,它在我的 fla 文件中设置为文档类。 我在 src 文件夹中有我的 Main 类的包结构,在 se.qmd.spaceInvaders 和 se.qmd.starLight 中有我的子类.我还使用 TweenMax 并将其保存在 src 文件夹中的“正常”包结构中。
在 Main 类中,我向舞台添加了一个 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;
}
}
}
只要我从 ShipHandler 调用 startMove 或 update 方法,我就会收到上面写的错误。 将不胜感激任何帮助,因为在我看来我必须做一些根本错误的事情......
【问题讨论】:
标签: actionscript-3 actionscript