0

ボタンを作成し、画面に追加しようとすると、このエラーが発生します。ボタンのコードは -

private function submitButton():void {
  submit_button=new SimpleButton();
  submit_button.x=200;
  submit_button.y=200;
  submit_button.upState=buttonShape();
  submit_button.overState=buttonShape();
  submit_button.downState=buttonShape();
}

private function buttonShape() {
  var rectangle:Shape = new Shape; // initializing the variable named rectangle
  rectangle.graphics.beginFill(0x8C2B44); // choosing the colour for the fill, here it is red
  rectangle.graphics.drawRect(200, 200, 300,20); // (x spacing, y spacing, width, height)
  rectangle.graphics.endFill();
}

私はそれを public var として宣言し、使用していますaddChild(submit_button);

  • 編集 - すべてのコードは 1 つのクラス ファイルにあります。最初に送信ボタンを設定します - private var submit_button:SimpleButton; 関数 private function submitButton():void { submit_button=new SimpleButton(); があります。submit_button.x=200; submit_button.y=200;

        submit_button.upState=buttonShape();
        submit_button.overState=buttonShape();
        submit_button.downState=buttonShape();
    
    } and the drawing function seen above. and i add it to the stage in another function  - private function gameOver():void {
    
        addChild(submit_button);
        addChild(gameOver1);      basically this function is called on a hit test. and i have a text box that appears (this works) but when i add the button i get the error
    
4

1 に答える 1

2

関数buttonShape()は何も返していません。あなたの最初の行var rectangle:Shape = new Shape;は、スコープ外になり、関数の最後に存在しなくなるローカル変数を作成しています。

何も返さないためbuttonShape()、実際の関数シグネチャは次のとおりです。

private function buttShape():void {}

関数の最後にあるreturn void;ことを意味します。

これは、あなたのコードが

submit_button.upState=buttonShape();

基本的に次のようにコンパイルされます。

submit_button.upState=null;
于 2011-04-03T23:02:09.287 に答える