4 Replies Latest reply: Oct 20, 2012 5:12 AM by Ned Murphy RSS

    error 1006: addToValue Function Problems. Please Help!

    Ben Hutchinson Community Member

      Hello people, im new to as3 and flash cs6 so i need some help. Im trying to create a mobile app, and have gone fairly well so far (all my hair is grey now), and i need some help with score resetting and just basic code touchups. Heres my main as class. (Game.as)

      [as]

      package

      {

                import flash.display.MovieClip;

                import flash.utils.Timer;

                import flash.events.TimerEvent;

                import flash.ui.Mouse;

                import flash.events.KeyboardEvent;

                import flash.ui.Keyboard;

                import flash.events.Event;

                import flash.media.SoundChannel;

       

       

                public class Game extends MovieClip

                {

       

       

                          static var ship:MovieClip;

                          static var healthMeter:HealthMeter;

                          static var score:Score;

                          static var enemyShipTimer:Timer;

                          static var gameOverMenu:GameOverMenu;

                          static var startMenu:StartMenu;

                          static var startButton:StartButton;

                          static var pauseButton:PauseButton;

                          static var playButton:PlayButton;

                          static var mainMenuButton:MainMenuButton;

                          public var currentValue:Number;

       

       

                          public function Game()

                          {

                                    Key.initialize(stage);

                                    ship = new Ship();

                                    healthMeter = new HealthMeter();

       

       

                                    healthMeter.x = 2.5;

                                    healthMeter.y = 576;

       

       

                                    gameOverMenu = new GameOverMenu();

                                    gameOverMenu.x = 217;

                                    gameOverMenu.y = 244;

                                    addChild(gameOverMenu);

                                    gameOverMenu.visible = false;

       

       

                                    gameOverMenu.playAgainButton.addEventListener("mouseDown", newGame);

                                    addEventListener(Event.DEACTIVATE, PauseGame);

       

       

       

       

                                    startMenu = new StartMenu();

                                    mainMenuButton = new MainMenuButton();

                                    startButton = new StartButton();

                                    startMenu.x = 151;

                                    startMenu.y = 111;

                                    startButton.x = 93;

                                    startButton.y = 426;

                                    mainMenuButton.x = 656;

                                    mainMenuButton.y = 483;

                                    addChild(mainMenuButton);

                                    mainMenuButton.visible = false;

                                    stage.addChildAt(startMenu, 0);

                                    addChild(startButton);

                                    startMenu.visible = true;

                                    startButton.visible = true;

       

       

                                    startMenu.visible = true;

       

       

                                    startButton.addEventListener("mouseDown", newGame);

                                    mainMenuButton.addEventListener("mouseDown", mainMenu);

       

       

                                    pauseButton = new PauseButton();

                                    pauseButton.x = 896;

                                    pauseButton.y = 63;

       

       

                                    pauseButton.addEventListener("mouseDown", PauseGame);

       

       

       

       

                                    playButton = new PlayButton();

                                    playButton.x = 896;

                                    playButton.y = 63;

                                    addChild(playButton);

                                    playButton.visible = false;

       

       

                                    playButton.addEventListener("mouseDown", PlayGame);

       

       

                          }

       

       

                          static function gameOver()

                          {

                                    mainMenuButton.visible = true;

                                    healthMeter.visible = false;

                                    pauseButton.visible = false;

                                    gameOverMenu.visible = true;

                                    enemyShipTimer.stop();

                                    for (var i in EnemyShip.list)

                                    {

                                              EnemyShip.list[i].kill();

                                    }

                                    ship.takeDamage(-ship.maxHealth);

                          }

                          function newGame(e:Event)

                          {

                                    gameScore.visible = true;

                                    addChild(pauseButton);

                                    addChild(healthMeter);

                                    addChild(mainMenuButton);

                                    enemyShipTimer = new Timer(1500);

                                    enemyShipTimer.addEventListener("timer", sendEnemy);

                                    addChild(ship);

                                    healthMeter.visible = true;

                                    startMenu.visible = false;

                                    mainMenuButton.visible = false;

                                    startButton.visible = false;

                                    healthMeter.visible = true;

                                    pauseButton.visible = true;

                                    playButton.visible = false;

                                    gameOverMenu.visible = false;

                                    ship.visible = true;

                                    ship.x = -2.85;

                                    ship.y = 469;

                                    enemyShipTimer.start();

                          }

                          function mainMenu(e:Event)

                          {

                                    gameScore.visible = false;

                                    removeChild(mainMenuButton);

                                    removeChild(ship);

                                    healthMeter.visible = false;

                                    startMenu.visible = true;

                                    mainMenuButton.visible = false;

                                    startButton.visible = true;

                                    healthMeter.visible = false;

                                    pauseButton.visible = false;

                                    playButton.visible = false;

                                    ship.takeDamage(ship.maxHealth);

                                    gameOverMenu.visible = false;

                          }

                          function PauseGame(e:Event)

                          {

                                    enemyShipTimer.removeEventListener("timer", sendEnemy);

                                    stage.frameRate = 0;//

                                    pauseButton.visible = false;

                                    playButton.visible = true;

                          }

                          function PlayGame(e:Event)

                          {

                                    enemyShipTimer.addEventListener("timer", sendEnemy);

                                    stage.frameRate = 30;//

                                    pauseButton.visible = true;

                                    playButton.visible = false;

                          }

       

       

       

       

                          function sendEnemy(e:Event)

                          {

                                    var enemy = new EnemyShip();

                                    stage.addChildAt(enemy, 0);

                                    gameScore.addToValue(1);

                          }

                          function getFinalScore():Number

                          {

                                    return gameScore.currentValue;

                          }

                          function Counter()

                          {

                                    reset();

                          }

       

       

                          function addToValue( amountToAdd:Number ):void

                          {

                                    currentValue = currentValue + amountToAdd;

                                    updateDisplay();

                          }

       

       

                          public function setValue( amount:Number ):void

                          {

                                    currentValue = amount;

                                    updateDisplay();

                          }

       

       

                          public function reset():void

                          {

                                    currentValue = 0;

                                    updateDisplay();

                          }

       

       

                          public function updateDisplay():void

                          {

                                    super.updateDisplay();

                                    score.scoreDisplay.text = currentValue.toString();

                          }

       

       

                }

      }

      [/as]

       

       

      Any help will be greatly appreciated. The actuall error is

       

      "

      Attempting to launch and connect to Player using URL I:/SFUR/APP/APP-app.xml

      [SWF] APP.swf - 57874 bytes after decompression

      TypeError: Error #1006: addToValue is not a function.

                at Game/sendEnemy()[I:\SFUR\APP\Game.as:154]

                at flash.utils::Timer/_timerDispatch()

                at flash.utils::Timer/tick()

      Debug session terminated.

      "

      Thanks for your support

       

      -Ben

       

      Edit: if you need to see any of my other classes (as files lol) just ask me

        • 1. Re: 1006: addToValue Function Problems.
          Ned Murphy CommunityMVP

          You should check your posting before leaving it for others to ponder.  Your code is all over the place.  I don't know why but I took the time to unscramble it so that I could read/follow it.

           

          The problem is probably related to this line....

           

                gameScore.addToValue(1);

           

          While you do have a function named addToValue, I am unable to determine that you have an object named gamesScore that also has such a function.

           

          A number of your functions are missing the public/private designation.

          • 2. Re: 1006: addToValue Function Problems.
            TheNachoman Community Member

            thanks! i have a new thread i posted with a more detailed problem. see the latest one by TheNachoman. I have dynamic text called gameScore that i want to add the value too. Thanks!

            • 3. Re: 1006: addToValue Function Problems.
              TheNachoman Community Member

              maybe if i pm you, if i can, my whole flash document (fla as files everything) and could you please edit it to make a working score? I will be extremely greatful! I understand if your short on time though... I just want a score that counts up when a enemy tnt either spawns or despawns (preferably despawns) and a highscore thing next to the score on top displaying your highest score by using sharedobject or something similar. I will be so pleased if you could do this for me or link me in the right direction! THANKYOU x1000 lol

              • 4. Re: 1006: addToValue Function Problems.
                Ned Murphy CommunityMVP

                I offer help freely in the forums.  Otherwise, I do what you are asking about for a living.