Debugging

16 posts

Flag Post

So hey its me again, i was wondering how you experts locate the bug and how to debug it ?

I keep getting this error
TypeError: Error #1006: addToValue is not a function.
at AvoiderGame/onTick()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

I already defined addToValue in Counter before, can you experts teaches me how to debug or maybe gives me the possibility how this kind of error will happens ?
( Im new in coding, i started coding 3 days ago) and btw the website im learning from is here

http://gamedev.michaeljameswilliams.com/2009/02/03/avoider-game-tutorial-5/

I tried to copy codes from the Developer but i still seems to be doing it wrong i can’t get to implant Second Lasted inside the Game Over Screen.

Experts please teach me how to debug .-. Its getting frustrating i have been stuck on this part for 3 hours

 
Flag Post

Oh I forgot something, do you have websites to discuss about coding 24/7 , i mean so they can help me when i met troubles in coding

 
Flag Post

Can you post your code for the Counter class and the AvoiderGame class?

 
Flag Post

Okay,
This is the AvoiderGame.as

package 
{
	import flash.display.MovieClip;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.ui.Mouse;

	public class AvoiderGame extends MovieClip 
	{
		public var enemy:Enemy;
		public var army:Array;	
		public var avatar:Avatar;
		public var gameTimer:Timer;
 
		public function AvoiderGame() 
		{
			Mouse.hide();
			army = new Array();
			var newEnemy = new Enemy( 100, -15 );
			army.push( newEnemy );
			addChild( newEnemy );
			
			avatar= new Avatar();
			addChild( avatar );
			avatar.x= mouseX;
			avatar.y= mouseY;
 
			gameTimer = new Timer( 25 );
			gameTimer.addEventListener( TimerEvent.TIMER, onTick );
			gameTimer.start();
		}
		
		public function onTick( timerEvent:TimerEvent ):void 
		{	
			gameClock.addToValue( 25 );			
			if ( Math.random() < 0.1 )				
			{
				var randomX:Number = Math.random() * 400;
				var newEnemy:Enemy = new Enemy( randomX, -15 );
				army.push( newEnemy );
				addChild( newEnemy );
				gameScore.addToValue( 10 );
			}
			avatar.x = mouseX;
			avatar.y = mouseY;
			

			for each ( var enemy:Enemy in army ) 
			{
				enemy.moveDownABit();
				if ( avatar.hitTestObject( enemy ) ) if ( PixelPerfectCollisionDetection.isColliding( avatar, enemy, this, true ) )
				{
					gameTimer.stop();
					dispatchEvent( new AvatarEvent( AvatarEvent.DEAD ) );
				}
			}
		}	
		public function getFinalScore():Number
		{
		return gameScore.currentValue;
		}
		public function getFinalClockTime():Number
		{
			return gameClock.currentValue;
		}
			
	}
}

and this is Counter Class

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
		{
			
		}
	}
}

The error is coming out from this line gameClock.addToValue( 25 );

 
Flag Post

Hello,

Firstly please use the tags listed in the “How to format” sticky in this forum.

Secondly and in regards to your error, have you created a gameScore and a gameClock symbol and exported them for use with actionscript with those names?

 
Flag Post
Originally posted by Pixel_Chaos:

Hello,

Firstly please use the tags listed in the “How to format” sticky in this forum.

Secondly and in regards to your error, have you created a gameScore and a gameClock symbol and exported them for use with actionscript with those names?

I’d like to reiterate Pixel_Chaos’s request that you use the appropriate tags to post your code. Just to clarify the symbol and class names, you’re supposed to have MovieClips named Clock and Score, and they should be linked to classes of the same name. Please verify that this is so. The names gameScore and gameClock are instances of Score and Clock respectively. Both should be present with those instance names on your PlayScreen MovieClip.

It seems that the Clock class also has a function called addToValue. Can you please post the code of your Clock class?

 
Flag Post

Uh no the Clock dosen’t have addToValue function

package
{
	import flash.display.MovieClip;
	public class Clock extends Counter
	{
		public function Clock()
		{
			super();
		}
 
		override public function updateDisplay():void
		{
			super.updateDisplay();
 
			var frameToSkipTo:Number = currentValue / 1000;
			frameToSkipTo = Math.floor( frameToSkipTo );
			frameToSkipTo = frameToSkipTo + 1;
			while ( frameToSkipTo > 21 )
			{
			frameToSkipTo = frameToSkipTo - 21;
			}
			clockDisplay.gotoAndStop( frameToSkipTo );
 
		}
	}
}
 
Flag Post

The truth is I have no idea where the problem is coming out of , @ Pixel_Chaos, actually gameScore and gameClock is the instance name from Score and Clock as Elyzius already said it, I already named it with Instance name on my playScreen, and btw what do you mean by “linked to classes of the same name” I don’t quite understand that sentences

 
Flag Post
Originally posted by fatboy8898:

and btw what do you mean by “linked to classes of the same name” I don’t quite understand that sentences

It just means that the Clock MovieClip should be linked to the Clock class, and the Score MovieClip should be linked to the Score class. Take a look at the following example from MJW’s Avoider tutorial:

The above picture shows that the Enemy MovieClip is linked to a class that is also named Enemy, as shown in the blue highlighted text. Please check that your Clock MovieClip is linked to the Clock class. I suspect that it isn’t, and that may be causing your game to crash. There doesn’t seem to be anything wrong with your code.

 
Flag Post

Where is gameScore declared?

 
Flag Post

gameScore is an instance of Score that is already positioned in the playScreen MovieClip.

 
Flag Post

Uh elyzius I already linked Clock MovieClip to Clock.as, and Score to Score.as, I have no idea what i did wrong .-.

 
Flag Post

Can you zip and upload your FLA and all your AS files so I can take a look at them? If you need a file hosting site, Mediafire seems to be a popular one.

 
Flag Post

All right, I see what the problem is. Take a look at the clock in your playScreen. When you click it, look at its properties. Notice that it’s an instance of StopWatch, not Clock.

To correct the error, click the Swap button that is beside “Instance of: StopWatch” then choose the Clock symbol in the window that appears. When you run it, you’ll find that your earlier error is gone.

Instead, it is replaced by another error: TypeError: Error #1009: Cannot access a property or method of a null object reference. The problem is that you have more than one frame in your Clock class, but the StopWatch symbol is only in the first frame. All the other frames contain Shape objects. In other words, your Clock is a MovieClip with another MovieClip that is embedded only in its first frame. Since the Clock symbol has 21 frames, 20 out of 21 times, clockDisplay is null.

To fix the problem, delete all but the first frame of your Clock symbol’s timeline then save all your changes. Your game will then run perfectly.

 
Flag Post

Oh thank god, It runs fine, You’re god Elyzius :D Oh btw why you don’t go and create a game yourself since you know so much about Programming,please tell me where did you learn all of those from :D

 
Flag Post

Lol. I did create a game, but it was bad. I only had 10 days to do it though, and it was my very first Flash computer game of any kind, so I guess my first effort can be excused. Those who participated in or voted on GiTD #27 would know what game I’m talking about.

As for where I learned Flash programming, it’s from the same source you’re going through now — Michael J. William’s Avoider tutorial. It’s one of the best tutorials on the Web if not the very best.