他のクラスでアクセスできるように、ステージ用のシングルトン クラスを作成したプログラムがあります。
テキストを含む他のシンボルがいくつかあるため、コードでテキストを変更する必要があります。
私の問題は、Classic Text の代わりに TLF テキストを使用するたびに、シングルトン ステージ クラスを参照するすべてのクラスが "TypeError: Error #1009: Cannot access a property or method of a null object reference."
TLFテキストで正常に動作する以前のプログラムがありますが、ステージにシングルトンクラスを使用したのはこれが初めてなので、何らかの形でそれが含まれていると思います。
関連する問題 (公開設定など) について見た他の投稿でいくつかの解決策を試しましたが、これまでのところ何も機能していません。
以下は、最初のエラーが発生する場所です。
// Constructor
public function Zoom(object:MovieClip) {
// Set the stage
stage = StageManager.instance.stage;
// Set the zoom object
zoomObject = object;
// Add event listener for the mouse wheel
stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseZoom); // ERROR OCCURS HERE
if (Controls.instance.controls.zoomInBtn && Controls.instance.controls.zoomOutBtn) {
Controls.instance.controls.zoomInBtn.addEventListener(MouseEvent.CLICK, zoomIn);
Controls.instance.controls.zoomOutBtn.addEventListener(MouseEvent.CLICK, zoomOut);
}
}
シングルトンクラスは次のとおりです。
package {
import flash.display.Stage;
// Singleton class so any other classes can access the stage.
public class StageManager {
// Publicly accessible singleton instance
public static var instance:StageManager = new StageManager();
private var m_stage:Stage;
// Getters and Setters
public function set stage(stg:Stage):void {
m_stage = stg;
}
public function get stage():Stage {
return m_stage;
}
}
}