這裏的屬性或方法是我的整個調試錯誤:AS3:無法訪問空對象引用
Car initiated: [object MovieClip]
Wheel initiated: [object MovieClip]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.George.MegaAmazingApp.Components::Wheel/clickHandler()[C:\Documents and Settings\reithg\My Documents\Classes\com\George\MegaAmazingApp\Components\Wheel.as:24]
[UnloadSWF] GeorgesMegaAmazingApp.swf
Test Movie terminated.
Car.as:
package com.George.MegaAmazingApp.Components
{
import flash.display.MovieClip;
public class Car extends MovieClip
{
public var carObj:MovieClip;
public function Car(carObj:MovieClip)
{
trace("Car initiated: " + carObj)
this.carObj = carObj;
}
public function Accelerate(speed:Number)
{
carObj.y -= speed;
}
}
}
Wheel.as
package com.George.MegaAmazingApp.Components
{
import flash.display.Stage;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.MovieClip;
public class Wheel extends Car
{
public var rotated:Number;
public var wheelObj:MovieClip;
public function Wheel(wheelObj:MovieClip, carObj:MovieClip)
{
super(carObj);
this.carObj = carObj;
this.wheelObj = wheelObj;
trace("Wheel initiated: " + wheelObj);
wheelObj.addEventListener(MouseEvent.CLICK, clickHandler);
}
private function clickHandler(event:MouseEvent):void
{
stage.addEventListener(Event.ENTER_FRAME, super.Accelerate(2));
}
}
}
和我的SWF啓動它:
import com.George.MegaAmazingApp.Components.*;
var wheelObj:Wheel = new Wheel(this.wheel,this.car);
任何人都知道最新錯了嗎?
車輪延伸車?我看到我頭腦裏開着的奇怪事物。無論如何,這是carboj是'空',但在你提供的代碼中沒有任何地方可以看到它是如何實例化的... – RIAstar
車輪實際上是方向盤並作爲汽車的遙控器工作。 carObj應該是'this.car'(我是OOP的新手,所以很可能我錯過了一些我不知道的東西,像幾個小時新的新東西)。 –
是的,但是'this.car'在哪裏實例化?因爲它顯然是'null'。 – RIAstar