Recent posts by asgerregsa on Kongregate

Flag Post

Topic: Game Programming / TypeError: Error #2007: Parameter hitTestObject must be non-null.

I’m making the Shootorial game in AS3. I’m following it step by step and I’m on page 4 of this part: http://www.kongregate.com/games/Moly/shootorial-5-actionscript-3?acomplete=shootorial+%234%3A+actionscript+3

I have a code that is supposed to make it so that when the player (ship) collides with an enemy, the enemy (EnemyShip) is removed from the stage.

Here is the code, which I have copied from the Shootorial:

package{
	import flash.display.MovieClip;
	import flash.events.Event;
	public class EnemyShip extends MovieClip{
	
		var speed:Number;
		
		function EnemyShip(){
			this.x = 700;
			this.y = Math.random()*200 + 50;
			speed = Math.random()*5 + 5;
			
			addEventListener("enterFrame", enterFrame);
			
		}//End EnemyShip
			function enterFrame(e:Event){
				this.x -= speed;
				if(this.x < -100){
				removeEventListener("enterFrame", enterFrame);
				stage.removeChild(this);
				}//End if statement
				
			if(this.hitTestObject(Game.ship)){
				kill();
			}//End if statement
				
			
			}//End enterFrame function
				function kill(){
					removeEventListener("enterFrame", enterFrame);
					stage.removeChild(this);
				}//End kill function
		
	}//End movieclip
}//End package

Whenever I try to test the movie, when I hit an enemy, it doesn’t disappear. I just constantly get this error in the output.

TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/flash.display:DisplayObject::_hitTest()
at flash.display::DisplayObject/hitTestObject()
at EnemyShip/::enterFrame()

I don’t know what it means, so it would be nice if you would help me.

Thanks in advance,
Asger.

 
Flag Post

Topic: Game Programming / gotoAndStop (AS3) [Solved]

You don’t need to instantiate a new Array, just do

wallsArray = [];

I don’t know what’s best. I just did this:

wallsArray.length = 0;
 
Flag Post

Topic: Game Programming / gotoAndStop (AS3) [Solved]

Originally posted by vesperbot:

Clear the array in “createArray()” function.

Thank you, it works now :)

 
Flag Post

Topic: Game Programming / gotoAndStop (AS3) [Solved]

Yup, that was the problem. Thank you guys :)

Now I have another problem XD

My walls are instance named through an array.
Now, when I go to the next frame, the walls are placed differently, but I still lose if I hit one of the “invisible” walls – the walls that were there in level 1. I can’t figure out how to solve this. (This is also my first game in AS3).


stop();

import flash.ui.Mouse;
import flash.events.KeyboardEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;

stage.addEventListener(Event.ENTER_FRAME, gameLoop);
ball.addEventListener(MouseEvent.CLICK, mouseClickHandler);
ball.addEventListener(MouseEvent.CLICK, ballClickHandler);

Mouse.show();

var follow:Boolean=false; //FOLLOW MOUSE\\
var mouseVisible:Boolean=true;//MOUSE VISIBILITY\\
var wallsArray=new Array();//WALLS' INSTANCE NAMES VAR\\



createArray();


//the walls' instance names
function createArray():void{
	for(var i:int = 0; i<this.numChildren;i++){
		if(this.getChildAt(i) is wall){
			wallsArray.push(this.getChildAt(i));
			}
		}
	}
	
function gameLoop(e:Event):void{
	moveBall();
	if(ball.hitTestObject(finish)){
		gotoAndStop(3);
		} else {
		
		}
}
	
	function mouseClickHandler(e:MouseEvent):void{
	if (mouseVisible == true) {
         Mouse.hide()
         mouseVisible = false;
    } else {
         Mouse.show()
         mouseVisible = true;
    }
}
	
function moveBall():void{//BALL MOVEMENT\\
	if(follow){
		ball.x=mouseX;
		ball.y=mouseY;		
		}
		for (var i:int = 0; i<wallsArray.length; i++){
			if(ball.hitTestObject(wallsArray[i])){
				follow=false;
				Mouse.show();
				mouseVisible=true;
				ball.x=235;
				ball.y=201;
				}
			}
	}
	

	
function ballClickHandler(e:MouseEvent):void{//FOLLOW MOUSE\\
	follow=true;
	mouseVisible=false;
}

 
Flag Post

Topic: Game Programming / gotoAndStop (AS3) [Solved]

Hello
I am making a maze game with my first level on frame 2. I want it so that when you (instance name: ball) hit the finish (instance name: finish) you go to frame 3.
However, when I try to make this code:


stage.addEventListener(Event.ENTER_FRAME, gameLoop);

function gameLoop(e:Event):void{
	moveBall();
	if(ball.hitTestObject(finish)){
		gotoAndStop(3);
		} else {
		
		}
}

…I get this message in the output, and I don’t know what it means:

“TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/flash.display:DisplayObject::hitTest()
at flash.display::DisplayObject/hitTestObject()
at mazeas3
_fla::MainTimeline/gameLoop()”

 
Flag Post

Topic: Game Programming / Cursor follows mouse even though told not to [Solved]

Originally posted by dragon_of_celts:

You have “follow:false” instead of “follow=false”.

Thanks. It works now :)

 
Flag Post

Topic: Game Programming / Cursor follows mouse even though told not to [Solved]

Hello
I am making a maze game where the cursor is a ball with the instance name “ball”.
The walls are given instance names based on an array.
The idea is, that when you load the level, you are gonna have your normal cursor, but then when you click on the ball, you control that with the mouse.
Then when you hit a wall, the ball goes back to its starting position, and follow=false; making you have to click the ball again to control it.
However, when you hit a wall, the ball still follows the mouse cursor around.


stage.addEventListener(Event.ENTER_FRAME, gameLoop);
ball.addEventListener(MouseEvent.CLICK, ballClickHandler);

var follow:Boolean=false; //BALL MOVEMENT

var wallsArray=new Array();

createArray();


//THE WALLS' INSTANCE NAMES. I PLACED SEPERATE WALLS ON THE MAP
//AND JUST RESIZED THEM
function createArray():void{
	for(var i:int = 0; i<this.numChildren;i++){
		if(this.getChildAt(i) is wall){
			wallsArray.push(this.getChildAt(i));
			}
		}
	}
	
function gameLoop(e:Event):void{
	moveBall();
	}
	
function moveBall():void{//HERE IS THE PART ABOUT THE BALL MOVEMENT
	if(follow){
		ball.x=mouseX;
		ball.y=mouseY;
		}
		for (var i:int = 0; i<wallsArray.length; i++){
			if(ball.hitTestObject(wallsArray[i])){
				follow:false;
				ball.x=235;
				ball.y=201;
				}
			}
	}
	
function ballClickHandler(e:MouseEvent):void{
	follow=true;	
}

Here is the SWF: http://www.swfcabin.com/open/1364079247

 
Flag Post

Topic: Game Programming / Problems with my simple maze game [Solved]

Originally posted by tonikovacic:

Piece of advice, dont go as2, its a waste of time. go as3

Okay, thanks for the advice. I just don’t know how to get started on as3.

 
Flag Post

Topic: Game Programming / Problems with my simple maze game [Solved]

Hello
I’m making a mouse maze game with a custom cursor that has the instance name of “cursor.”
I actually have two issues in this:
1:
If you click and hold, you can go through the walls with the mouse and therefore cheat your way through the level.
2:
If the cursor overlaps the wall a little bit, you don’t fail because the mouse is 19.5X19.5 px and I have this code in the wall:


on(rollOver){
	gotoAndStop(5);
}

I’m getting into as2 for the first time in 3 years, so I’ve forgotten most of my knowledge of the language.
If any of you could help me, it would be really nice.

Thanks in advance,
Asger

 
Flag Post

Topic: Game Programming / Pausing my Timer

Hello.
I am making a maze game that keeps track of how fast you are.
I have a timer on level 1 of the game that goes up, counting hours, minutes, seconds and milliseconds. I wanna have a frame between each level that shows you how fast you beat that level, and there should be a button to the next level. And then the timer would continue from where it stopped, so that when you beat the game, your overall time goes on a highscore with the Kongregate API.

I found this code in a really helpful tutorial (Emanuele Feronato):

start_time = getTimer();

onEnterFrame = function () {
	elapsed_time = getTimer()-start_time;
	_root.count.text = time_to_string(elapsed_time);
	
};
function time_to_string(time_to_convert) {
	elapsed_hours = Math.floor(time_to_convert/3600000);
	remaining = time_to_convert-(elapsed_hours*3600000);
	elapsed_minutes = Math.floor(remaining/60000);
	remaining = remaining-(elapsed_minutes*60000);
	elapsed_seconds = Math.floor(remaining/1000);
	remaining = remaining-(elapsed_seconds*1000);
	elapsed_fs = Math.floor(remaining/10);
	if (elapsed_hours<10) {
		hours = "0"+elapsed_hours.toString();
	} else {
		hours = elapsed_hours.toString();
	}
	if (elapsed_minutes<10) {
		minutes = "0"+elapsed_minutes.toString();
	} else {
		minutes = elapsed_minutes.toString();
	}
	if (elapsed_seconds<10) {
		seconds = "0"+elapsed_seconds.toString();
	} else {
		seconds = elapsed_seconds.toString();
	}
	if (elapsed_fs<10) {
		hundredths = "0"+elapsed_fs.toString();
	} else {
		hundredths = elapsed_fs.toString();
	}
	return hours+":"+minutes+":"+seconds+":"+hundredths;
}

That code goes in the timeline.

Thanks in advance,
Asger

 
Flag Post

Topic: Game Programming / Virus-Free Adobe Flash and/or Photoshop.

Hi.
I want to start making games again on my new computer, I don’t have my old one anymore. But to make games you need to have the software required. I am very familiar with Adobe Flash and Photoshop, however I don’t have a million dollars so I can buy it. That’s why I have decided to get the software in a cheaper (free) way.
Does anyone know where I can get the programs for free? I don’t care if it’s CS3, CS4 or CS5. Where did you get yours?

Thanks in advance.
Asger

 
Flag Post

Topic: Game Programming / Maze game won't work

Hi.
I’m making a maze game. When you roll over the wall (button) you go to frame 3 which is a menu.
This is my code inside of the wall:

on (rollOver){
gotoAndStop(3)
}
on(rollOut){
gotoAndStop(3);
}

This code is the same on the wall in level 1 and level 2 but works perfectly fine in level 1. What should I do?

 
Flag Post

Topic: Kongregate / How to shot blue portals ?

It would be cool if you got a real cake, lol

 
Flag Post

Topic: Game Programming / AttachMovie problems

Thank you very much but how do you correct that?

 
Flag Post

Topic: Game Programming / AttachMovie problems

For your current problem in spaceBob you did this _x -= 15 that is not right.

Thank you very much but if that is not right, what is right?

 
Flag Post

Topic: Game Programming / AttachMovie problems

Here is it so you can see it: http://www.swfcabin.com/open/1289400959

 
Flag Post

Topic: Game Programming / AttachMovie problems

We want to see the code, not the language version ;)

Of course :|) Here is the whole code. voh is the background:


stop();

voh.onEnterFrame = function()
{
	voh._x -= 10;
	if(voh._x < -550)
	{
		voh._x = 0;
	}
}

var spaceInt:Number = setInterval(spaceBob, 4000);
var carInt:Number = setInterval(carBob, 4000);

function spaceBob(){
	var space:MovieClip = _root.attachMovie("space", "space"+_root.getNextHighestDepth(), _root.getNextHighestDepth()); 
	space._x = -40;
	space._y = 364;
	space.onEnterFrame = function(){
		_x -= 15;
	}
}


function carBob(){
	var car:MovieClip = _root.attachMovie("car", "car"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
	car._x = 727;
	car._y = 264;
	car.onEnterFrame = function(){
		car._x -= 15;
	}
}
carlsson.onEnterFrame = function(){
	if(Key.isDown(Key.SPACE)){
		this.gotoAndPlay(33);
	}
}

 
Flag Post

Topic: Game Programming / AttachMovie problems

I’m using as2. The “scene” is where you run on a road, towards the right side (sideways view). The road is moving towards left so it looks like you are running. But suddenly the road starts moving really fast towards left and the character which, until now, has been on the middle of the screen, goes off the screen.

 
Flag Post

Topic: Game Programming / AttachMovie problems

you are passing a string instead of a reference to the function you want to call, take the "" off and it should work.

Thank you very much but after those four seconds, the whole “scene”, if you will, speeds radically up. What is wrong?

 
Flag Post

Topic: Game Programming / AttachMovie problems

Thank you very much but they still don’t show up. I think there is something wrong with my setInterval.

var spaceInt:Number = setInterval("spaceBob", 4000);
var carInt:Number = setInterval("carBob", 4000);
 
Flag Post

Topic: Game Programming / AttachMovie problems

Hi people
I am making a game which is supposed to attach a couple of movieclips to the frame every four seconds.

Here is my code:


var spaceInt:Number = setInterval("spaceBob", 4000);
var carInt:Number = setInterval("carBob", 4000);

function spaceBob(){
	_root.attachMovie("space", "space", _root.getNextHighestDepth());
	space._x = 727;
	space._y = 264;
	space._x -= 15;
}


function carBob(){
	_root.attachMovie("car", "car", _root.getNextHighestDepth());
	car._x = 727;
	car._y = 264;
	car._x -= 15;
}

But the movie clips are never showing up. What am I doing wrong?

Hope you can help, Asger

 
Flag Post

Topic: Game Programming / Flash is not Bringing Character to Front! URGENT!

du har været en stor hjælp

 
Flag Post

Topic: Game Programming / Flash is not Bringing Character to Front! URGENT!

igen tak

 
Flag Post

Topic: Game Programming / Flash is not Bringing Character to Front! URGENT!

Thanks

 
Flag Post

Topic: Game Programming / Flash is not Bringing Character to Front! URGENT!

Hello Developers
I have a problem with flash cs3:
I have a character MC that’s supposed to be in front of my road MC. I click on “bring to front” on the character, and “send to back” on the road but the road is still overlapping the character.
Has any of you experienced this? What did you do?

Thanks in advance,
Asger