0

私にはばかげた間違いが隠れていると確信していますが、2時間以上それを行ってきましたが、何が問題なのかを見つけることができないようです. エラーはタイトルにあり、以下は私の関連コードです。

さらに役立つ詳細:

正確なエラーは次のとおりです。

TypeError: エラー #1006: addToValue は関数ではありません。SimpleMenuMain/onTick() で flash.utils::Timer/_timerDispatch() で flash.utils::Timer/tick()

ゲームは実行されますが、スコアがカウントされません。スコアをカウントしたいです。すべてのインスタンス名が正しいことを 3 回確認しましたが、実際に行ったことに問題はありません。どういうわけかそれらを間違って参照している可能性がありますが、コードで使用されているすべての名前は、シンボルやテキスト内のオブジェクトに含まれています...など.

お時間をいただきありがとうございます。これは本当に私を殺しています。

PS---私はチュートリアルに従っているので、不必要なことをしている場合でも、私を責めないでください! この難問に答えるのに役立つことに加えて、他のコメントは大歓迎ですが =)。

ドキュメント クラス

package 
{
    import flash.display.MovieClip;

    public class SMGDocClass extends MovieClip 
    {
        public var playScreen:SimpleMenuMain;
        public var titleScreen:TitleScreen;
        public var gameOver:GameOver;

        public function SMGDocClass() 
        {
            titleScreen = new TitleScreen();
            titleScreen.addEventListener(NavigationEvent.START,onRequestStart,false,0,true);
            titleScreen.x = 0;
            titleScreen.y = 0;
            addChild(titleScreen);

        }

        public function onStickman1Death(stickman1Event:Stickman1Event):void
        {
            var finalScore:Number = playScreen.getFinalScore();
            var finalClockTime:Number = playScreen.getFinalClockTime();

            gameOver = new GameOver();
            gameOver.addEventListener(NavigationEvent.RESTART,onRequestRestart,false,0,true);
            gameOver.addEventListener(NavigationEvent.MAINMENU,onRequestMainMenu,false,0,true);
            gameOver.x = 5;
            gameOver.y = 6;
            gameOver.setFinalScore( finalScore );
            gameOver.setFinalClockTime( finalClockTime );
            addChild(gameOver);

            playScreen = null;

        }

        public function onRequestStart( navigationEvent:NavigationEvent ):void
        {
        playScreen = new SimpleMenuMain();
        playScreen.addEventListener( Stickman1Event.DEAD, onStickman1Death,false,0,true );
        playScreen.x = 0;
        playScreen.y = 0;
        addChild( playScreen );

        titleScreen = null;
        }

        public function restartGame():void
        {
            playScreen = new SimpleMenuMain;
            playScreen.addEventListener(Stickman1Event.DEAD, onStickman1Death,false,0,true);
            playScreen.x = 0;
            playScreen.y = 0;
            addChild(playScreen);

            gameOver = null;
        }

        public function onRequestRestart(navigationEvent:NavigationEvent):void
        {
            restartGame();
        }

        public function onRequestMainMenu( navigationEvent:NavigationEvent):void
        {
            titleScreen = new TitleScreen();
            titleScreen.addEventListener(NavigationEvent.START,onRequestStart,false,0,true);
            titleScreen.x = 0;
            titleScreen.y = 0;
            addChild(titleScreen);

            removeChild(gameOver);
            gameOver = null;
        }

    }
}

playScreenクラス

package  {

    import flash.display.MovieClip;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    public class SimpleMenuMain extends MovieClip {

        public var army1:Array;
        public var enemy1:Enemy1;
        public var gameTimer:Timer;
        public var stickman1:Stickman1;

        public function SimpleMenuMain() {

            army1 = new Array();
            var newEnemy1 = new Enemy1( 100, -15 );
            army1.push(newEnemy1);
            addChild(newEnemy1);

            stickman1 = new Stickman1();
            addChild(stickman1);
            stickman1.x = mouseX;
            stickman1.y = mouseY;

            gameTimer = new Timer(25);
            gameTimer.addEventListener(TimerEvent.TIMER, onTick, false, 0, true);
            gameTimer.start();

        }

        public function onTick(timerEvent:TimerEvent):void
        {
            gameClock.addToValue( 25 );
            if ( Math.random() < 0.1 )
            {
                var randomX:Number = Math.random() * 400;
                var newEnemy1:Enemy1 = new Enemy1( randomX, -15 );
                army1.push( newEnemy1 );
                addChild( newEnemy1 );
                gameScore.addToValue( 10 );
            }

            stickman1.x = mouseX;
            stickman1.y = mouseY;

            for each (var enemy1:Enemy1 in army1)
            {
                enemy1.moveDown();

                if (stickman1.hitTestObject(enemy1))
                {
                    gameTimer.stop();
                    dispatchEvent(new Stickman1Event(Stickman1Event.DEAD));
                }
            }

        }

        public function getFinalScore():Number
        {
            return gameScore.currentValue;
        }

        public function getFinalClockTime():Number
        {
            return gameClock.currentValue;
        }

    }

}

カウンタークラス

package
{
    import flash.display.MovieClip;
    public class Counter extends MovieClip
    {
        public var currentValue:Number;

        public function Counter()
        {
            reset();
        }

        public function addToValue( amountToAdd:Number ):void
        {
            currentValue = currentValue + amountToAdd;
            updateDisplay();
        }

        public function reset():void
        {
            currentValue = 0;
            updateDisplay();
        }

        public function updateDisplay():void
        {

        }
    }
}

Stickman1Event クラス

package  
{
    import flash.events.Event;
    public class Stickman1Event extends Event 
    {
        public static const DEAD:String = "dead";

        public function Stickman1Event( type:String, bubbles:Boolean = false, cancelable:Boolean = false ) 
        { 
            super( type, bubbles, cancelable );

        } 

        public override function clone():Event 
        { 
            return new Stickman1Event( type, bubbles, cancelable );
        } 

        public override function toString():String 
        { 
            return formatToString( "Stickman1Event", "type", "bubbles", "cancelable", "eventPhase" ); 
        }
    }
}

NavigationEvent クラス

package  
{
    import flash.events.Event;
    public class NavigationEvent extends Event 
    {
        public static const RESTART:String = "restart";
        public static const START:String = "start";
        public static const MAINMENU:String = "mainmenu";

        public function NavigationEvent( type:String, bubbles:Boolean = false, cancelable:Boolean = false ) 
        { 
            super( type, bubbles, cancelable );

        } 

        public override function clone():Event 
        { 
            return new NavigationEvent( type, bubbles, cancelable );
        }

        public override function toString():String 
        { 
            return formatToString( "NavigationEvent", "type", "bubbles", "cancelable", "eventPhase" ); 
        }
    }
}

スコアクラス

package
{
    import flash.text.TextField;
    public class Score extends Counter
    {
        public function Score()
        {
            super();
        }

        override public function updateDisplay():void
        {
            super.updateDisplay();
            scoreDisplay.text = currentValue.toString();
        }

    }
}
4

1 に答える 1

1

Josh がすでに指摘しているように、gameScore および gameClock オブジェクトが実際に Counter のインスタンスであるという保証はありません。

インスタンス化するコード/場所を確認する必要があります。

いくつかの可能なオプション;

  • gameScore と gameClock は実際の Counter インスタンスではありません
  • カウンターを MovieClip としてインスタンス化しているため、カウンターをステージに追加しましたが、Library アセットと Counter クラスを正しく接続していない可能性があります。

Counter コンストラクターをこれに変更して実行できますか?

public function Counter()
{
    trace("i am a counter");
    reset();
}

... トレース出力が 2 回表示されます (gameScore と gameClock の場合)。トレース出力が表示されない場合、カウンターは構築されていません。つまり、gameScore と gameClock は単純な MovieClip インスタンスです。

于 2013-07-19T00:07:07.003 に答える