You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!

Author Search Results: 'goldleader23'

We found 31 matches.


<< < > >>

Viewing 1-30 of 31 matches. 1 | 2

2.

Happy

Topic: [AS3] hitTesting between classes?

Posted: 10/08/09 04:18 PM

Forum: Flash

I'll see what I can do with that, thanks! :)


3.

None

Topic: [AS3] hitTesting between classes?

Posted: 10/07/09 12:04 PM

Forum: Flash

I understand the concept, but not the implementation. This is my first "real" game, and I'm still not a very experienced programmer. I will, however, see if I can do anything with those collisions.

Thanks.


4.

None

Topic: [AS3] hitTesting between classes?

Posted: 10/06/09 03:02 PM

Forum: Flash

I'm sorry, could you elaborate a little more on the setup? I'm not asking you to do it for me, but my understanding isn't quite there yet. And how do you do collision detection without hitTest?


5.

Expressionless

Topic: [AS3] hitTesting between classes?

Posted: 10/02/09 04:15 PM

Forum: Flash

I hate not knowing what I'm doing. :(

I was using this series of tutorials [link], but because I had to change some things (specifically in this one [link]), I can't continue with the next tutorial ([link]), because it doesn't work.

Changes: I have two screens, a top view (scrolling downwards), and a side view (scrolling to the left). The player controls two ships, one on each screen. Whenever an enemy spawns, one spawns on each screen, and when one fires, so does the other one.

Problem: I had to put both enemy lasers into one random function inside my main "Engine" class, instead of in their corresponding enemy ship's classes. Now I can't do the hitTest in the tutorial for when an enemy laser hits one of the players ships.

Question: Can I either 1.) spawn each laser in it's own enemy's class (like in the tutorial), but still have both fire at a random interval at the same time (maybe saving every random number generated for one and applying it to the other?), or 2.) Set up the hitTest differently than the tutorial did, so it works with my current code?

Classes involved in this problem are Engine, Ship, Enemy1, and PurpleLaser. If anyone needs me to post some of them, I will. Not sure which might be needed, and posting all of them would make this post really long.

Thanks! :)


6.

None

Topic: [AS3] Interesting Problem

Posted: 09/03/09 01:55 PM

Forum: Flash

At 9/2/09 09:00 PM, ImpotentBoy2 wrote:
1, you don't need 2 enemy instances, you can have one class that that is displayed twice.

No I can't. I have 2 movie clips, one of the top view of a ship that flies downwards, and one of the side view of a ship that flies to the left. You can't link more than one movie clip to a class, so I need two classes.

At 9/2/09 09:58 PM, johnnymoha wrote: Can you not just have a random function in your main to create your ships and then have some logic to make sure that they have been created and then call yourship.firebullet(your ships x, your ships y) or something to which you can pass your ships current x,y and have it accelerate in whatever direction?

I guess I'll work with this a bit. I just didn't know if I could link the laser to the ship from the main class and not the ship class, much less how to do it. Hopefully I can get it to work.


7.

None

Topic: [AS3] Interesting Problem

Posted: 09/02/09 07:01 PM

Forum: Flash

I'll try to make it a little clearer.

I have an enemy ship that is being shown from two different angles at the same time (top and side), spawning at a random interval and flying across the screen. Because it's seen from two different angles at the same time, I needed to make 2 different enemy classes. Both of the views of the ship spawn at the same time, at a random interval. I have already coded this part.

I want the enemy (in both different views) to fire, also at a random interval. The enemy will just be shooting forward, not at anything. Both views of the ship are added to the stage in the "Main" class, in a random function. I can't add the lasers in the Main class because then they wouldn't be shot from the front of each ship. I need to add each laser to the stage in each enemy class for this to work (to my knowledge at least). If I use a random function in each ship class to fire the lasers, the random functions are independant of eachother, which wouldn't make sense because it's the same ship seen from two different angles at the same time, and therefore both should shoot simultaneously.

If I use a random function to fire the laser, on only one of the ship classes (for example, the top view), can I save whatever random values it generates and apply them to the other ship class?

Code, and maybe screenshots can be posted if there is still confusion.

Thanks! :)


8.

Resigned

Topic: [AS3] Interesting Problem

Posted: 09/01/09 08:29 PM

Forum: Flash

First, this is really hard to explain. I have two ships which are essentially the same ship from two different angles (and therefore flying two different directions). The two ships both spawn at a random interval, only they both spawn at the same time (but randomly). I hope that's not confusing. I'm trying to get the ships to fire at a random interval as well, both also firing at the same time (like they spawn). The problem is, both ships are placed onto the stage in the "Main" Class, and are therefore inside one "random" function, but in order to link both lasers to both ships (so they actually fire from the front of the ships), I need to link each laser class to each ship class separately, meaning two different random functions. Can I generate a random value for one of the lasers, save it, and apply it to the other laser, or is there another way to do it. If anyone has any questions, let me know.

Thanks! :)


9.

None

Topic: (AS3) Hittest using classes?

Posted: 07/21/09 02:31 PM

Forum: Flash

At 7/21/09 09:27 AM, henke37 wrote: You do not work with objects in the library, because there is no library when in the player. You work with instances of the defined classes that you have.

Unless I did something wrong (which is very likely), that didn't work either. I'll try out matrix5565's code later, unless anyone has any other ideas.


10.

Sad

Topic: (AS3) Hittest using classes?

Posted: 07/20/09 08:57 PM

Forum: Flash

I have a "Main" class linked to the stage, a "Ball" class linked to a ball, and a "Paddle" class linked to a paddle. The ball and paddle are both added to the stage through the Main class. I can't seem to find a way to reference the objects from the library to get the hittest to work. Any ideas? I can post code if needed. Thanks.


11.

None

Topic: [AS3] error help again :(

Posted: 07/07/09 01:24 AM

Forum: Flash

Nobody, huh?


12.

Resigned

Topic: [AS3] error help again :(

Posted: 07/04/09 10:29 PM

Forum: Flash

I just restructured my entire game, because it wasn't working right. I cleared up about 20 compiler errors and kept playing with stuff, but now I get this. It's been bugging me all day. I'm sure I'm just overlooking something, and there still might be a lot more work to do. Also, I'm still trying to figure out the whole "Class" thing, if anything seems off.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at vars$cinit()
	at global$init()[C:\Documents and Settings\Me\Desktop\Breakout\Flash Stuff\vars.as:11]
	at Breakout_fla::MainTimeline/frame1()[Breakout8_fla.MainTimeline::frame1:136]

A note on organization: I have code that covers the first three frames on one layer, and code that is for each of those frames individually on another layer. It looks like the error is pointing to line 136 (if I'm reading that right), but neither layer goes up that high, which led me to think it's combining the total lines of code. That also means I have no idea where to look for that part of the error.

main file, layer 1 (covers frames 1-3):

stop();

import flash.display.*;
import flash.events.*;

import blueBlock;
import lavenderBlock;
import redOrangeBlock;
import blackBlock;

import vars;

addEventListener(Event.ENTER_FRAME, movement);
addEventListener(KeyboardEvent.KEY_DOWN, checkKeys);
addEventListener(KeyboardEvent.KEY_UP, keyUps);
addEventListener(Event.ENTER_FRAME, pacBallFly);

function checkKeys(event:KeyboardEvent):void
{
	if (event.keyCode == 39)
	{
		vars.varRight = true;
	}
	if (event.keyCode == 37)
	{
		vars.varLeft = true;
	}
}

function keyUps(event:KeyboardEvent):void
{
	if (event.keyCode == 39)
	{
		event.keyCode = 0;
		vars.varRight = false;
	}
	if (event.keyCode == 37)
	{
		event.keyCode = 0;
		vars.varLeft = false;
	}
}

function movement(event:Event):void
{
	if (vars.varRight == true)
	{
		pacPaddle.x += vars.xspeed;
	}
	if (vars.varLeft == true)
	{
		pacPaddle.x -= vars.xspeed;
	}
	if (pacPaddle.hitTestObject(pacLeft))
	{
		pacPaddle.x += vars.xspeed;
	}
	if (pacPaddle.hitTestObject(pacRight))
	{
		pacPaddle.x -= vars.xspeed;
	}
}

function pacBallFly(event:Event):void
{
	pacBall.y -= vars.pacBallSpeedY;
	pacBall.x += vars.pacBallSpeedX;
	if (pacBall.hitTestObject(pacRight))
	{
		pacBall.x = 620;
		vars.pacBallSpeedX *= -1;
	}
	if (pacBall.hitTestObject(pacTop))
	{
		pacBall.y = 20;
		vars.pacBallSpeedY *= -1;
	}
	if (pacBall.hitTestObject(pacLeft))
	{
		pacBall.x = 20;
		vars.pacBallSpeedX *= -1;
	}
	if (pacBall.hitTestObject(pacPaddle))
	{
		pacBallAngle();
	}
	if (pacBall.hitTestObject(pacBottom))
	{
		vars.pacBallSpeedY *= -1;
		pacBall.x = 320;
		pacBall.y = 480;
		vars.balls --;
		if (vars.balls == 0)
		{
			removeEventListener(Event.ENTER_FRAME, pacBallFly);
			removeEventListener(Event.ENTER_FRAME, movement);
			removeEventListener(KeyboardEvent.KEY_DOWN, checkKeys);
			removeEventListener(KeyboardEvent.KEY_UP, keyUps);
			removeEventListener(Event.ENTER_FRAME, checkLvl);
			vars.gameOver = true;
			gotoAndStop('pacGameOver');
		}
	}
}

function pacBallAngle():void
{
	vars.pacBallSpeedX = vars.pacAnglePercent * 10;
	vars.pacBallSpeedY *= -1;
}

main file, layer 2 (covers only frame 1):

addEventListener(Event.ENTER_FRAME, checkLvl);

var pacLvl1:Array = new Array();

pacLvl1.push(new Array());
var pac1Row1:Array = new Array([0,0,0,0,0,1,1,1,1,0,0,0,0,0]);
var pac1Row2:Array = new Array([0,0,0,1,1,1,1,1,1,1,1,0,0,0]);
var pac1Row3:Array = new Array([0,0,1,1,1,1,1,1,1,1,1,1,0,0]);
var pac1Row4:Array = new Array([0,1,1,1,1,1,1,1,1,1,1,1,1,0]);
var pac1Row5:Array = new Array([0,1,1,1,2,2,1,1,2,2,1,1,1,0]);
var pac1Row6:Array = new Array([0,1,1,1,2,2,1,1,2,2,1,1,1,0]);
var pac1Row7:Array = new Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
var pac1Row8:Array = new Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
var pac1Row9:Array = new Array([1,1,2,2,1,1,2,2,1,1,2,2,1,1]);
var pac1Row10:Array = new Array([1,2,1,1,2,2,1,1,2,2,1,1,2,1]);
var pac1Row11:Array = new Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
var pac1Row12:Array = new Array([1,1,0,1,1,1,0,0,1,1,1,0,1,1]);
var pac1Row13:Array = new Array([1,0,0,0,1,1,0,0,1,1,0,0,0,1]);

pacLvl1[0].push(pac1Row1, pac1Row2, pac1Row3, pac1Row4, pac1Row5, pac1Row6, pac1Row7, pac1Row8, pac1Row9, pac1Row10, pac1Row11, pac1Row12, pac1Row13);

for (var k in pacLvl1[0])
{
	for (var i in pacLvl1[0][k][0])
	{
		if (pacLvl1[0][k][0][i] == vars.blue)
		{
			var block:blueBlock = new blueBlock();
			block.x = (i * (20)) + 190;
			block.y = (k * (20)) + 50;
			addChild(block);
		}
		else if (pacLvl1[0][k][0][i] == vars.lavender)
		{
			var block2:lavenderBlock = new lavenderBlock();
			block2.x = (i * (20)) + 190;
			block2.y = (k * (20)) + 50;
			addChild(block2);
		}
	}
}

function checkLvl(e:Event):void
{
	if(vars.blockAmt == 0)
	{
		gotoAndStop(nextFrame);
		removeEventListener(Event.ENTER_FRAME, checkLvl);
	}
}

blueBlock.as

package
{
	import flash.display.*;
	import flash.events.*;
	
	import vars;
	
	public class blueBlock extends MovieClip
	{
		public static var _root:MovieClip;
		public function blueBlock()
		{
			addEventListener(Event.ADDED, beginClass);
			addEventListener(Event.ENTER_FRAME, enterFrameEvents);
		}
		private function beginClass(event:Event):void
		{
			_root = MovieClip(root);
			vars.blockAmt ++;
		}
		private function enterFrameEvents(event:Event):void
		{
			if(vars.gameOver)
			{
				parent.removeChild(this);
				removeEventListener(Event.ENTER_FRAME, enterFrameEvents);
			}
			else if (this.hitTestObject(_root.pacBall))
			{
				vars.pacBallSpeedY *= -1;
				if ((_root.pacBall.x >= (x +10)) || (_root.pacBall.x <= (x -10)))
				{
					vars.pacBallSpeedY *= -1;
					vars.pacBallSpeedX *= -1;
				}
				parent.removeChild(this);
				vars.blockAmt --;
				removeEventListener(Event.ENTER_FRAME, enterFrameEvents);
			}
		}
	}
}

vars.as

package
{
	import flash.display.*;
	import flash.events.*;
	
	import blueBlock;
	import lavenderBlock;
	import redOrangeBlock;
	import blackBlock;
		
	public class vars
	{
		public static var varRight:Boolean = false;
		public static var varLeft:Boolean = false;
		public static var xspeed:Number = 10;
		public static var blockAmt:int = 0;
		public static var gameOver:Boolean = false;
		public static var pacBallSpeedX:Number = 5;
		public static var pacBallSpeedY:Number = 5;
		public static var balls:int = 3;
		public static var pacBallPosition:Number = blueBlock._root.pacBall.x - blueBlock._root.pacPaddle.x;
		public static var pacAnglePercent:Number = (pacBallPosition / (blueBlock._root.pacPaddle.width - blueBlock._root.pacBall.width));
		public static var blue:int = 1;
		public static var lavender:int = 2;
		public static var redOrange:int = 3;
		public static var black:int = 4;
	}
}

Sorry for the long post.


13.

None

Topic: [AS3]Flash doing things on its own?

Posted: 05/25/09 01:47 AM

Forum: Flash

dELtaluca: I removed the event listener you mentioned (and also noticed a missing semi-colon), but that didn't solve the problem.
Murudai: I did alot more on this than you think. I only come to the boards when I can't find any solution, either by trial and error or searching the net (I do plenty of both). I may be a noob, but I'm not lazy. I read the link you posted, and saw another on the site that might help, as well.

Looks like I'll be doing a bit more reading, then it's back to fiddling with my code for a while. Later, people.


14.

None

Topic: [AS3]Flash doing things on its own?

Posted: 05/24/09 02:06 PM

Forum: Flash

Alright, then, I have a few questions.
1. Can I import the classes I make into eachother? I already have a few classes I was importing onto the timeline (for each different type of block).
2. Can I put all of my variables in one class, or no?
3. Can I basically paste my code into a class, and then modify it to fit proper class structure?
4. Since the graphics change every three levels, will I have to place them all through code?

I do think I have a way to group every three levels together inside a class, and maybe also how to move from one class to the next. Unless, of course, I put the whole thing into one class.


15.

None

Topic: [AS3]Flash doing things on its own?

Posted: 05/23/09 10:47 PM

Forum: Flash

What exactly am I supposed to do with that? I have no idea how to not use frames, and know very little about classes. I need more info.


16.

Resigned

Topic: [AS3]Flash doing things on its own?

Posted: 05/23/09 07:59 PM

Forum: Flash

Interesting problem. First, I'm making a breakout game. My problem is, when I get a game over on the second level, it reloads the level instead of going to the game over frame, even though I put a "gotoAndStop". The first level goes to the game over frame like it's supposed to, so I copied and pasted the code from frame one, put it on frame two, changed the names of functions and variables accordingly, and this happens. The weirdest part is that I added a trace statement to the game over frame, to see if it actually went there, and it did, but still decided to go back and reload frame two again. No code is telling it to do that!

frame 2:

stop();
import redOrangeBlock;
import blackBlock;
var varRight2:Boolean = false;
var varLeft2:Boolean = false;
var xspeed2:Number = 10;
var blockAmt2:int = 0;
var gameOver2:Boolean = false;

stage.addEventListener(Event.ENTER_FRAME, movement2);
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeys2);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUps2);

function checkKeys2(event:KeyboardEvent):void
{
	if (event.keyCode == 39)
	{
		varRight2 = true;
	}
	if (event.keyCode == 37)
	{
		varLeft2 = true;
	}
}
function keyUps2(event:KeyboardEvent):void
{
	if (event.keyCode == 39)
	{
		event.keyCode = 0;
		varRight2 = false;
	}
	if (event.keyCode == 37)
	{
		event.keyCode = 0;
		varLeft2 = false;
	}
}
function movement2(event:Event):void
{
	if (varRight2 == true)
	{
		pacPaddle2.x += xspeed2;
	}
	if (varLeft2 == true)
	{
		pacPaddle2.x -= xspeed2;
	}
	if (pacPaddle2.hitTestObject(pacLeft))
	{
		pacPaddle2.x += xspeed2;
	}
	if (pacPaddle2.hitTestObject(pacRight))
	{
		pacPaddle2.x -= xspeed2;
	}
}

var pacLvl2:Array = new Array();
pacLvl2.push(new Array());
var pac2Row1:Array = new Array([0,0,0,0,0,0,0,0,0,0,3,3]);
var pac2Row2:Array = new Array([0,0,0,0,0,0,0,0,3,3,3,3]);
var pac2Row3:Array = new Array([0,0,0,0,0,0,3,3,0,3,0,0]);
var pac2Row4:Array = new Array([0,0,0,0,0,3,0,0,0,3,0,0]);
var pac2Row5:Array = new Array([0,3,3,3,3,0,0,0,3,0,0,0]);
var pac2Row6:Array = new Array([3,3,3,4,3,3,0,3,0,0,0,0]);
var pac2Row7:Array = new Array([3,3,3,3,3,0,3,4,3,3,3,0]);
var pac2Row8:Array = new Array([3,4,3,3,0,3,3,4,3,3,3,0]);
var pac2Row9:Array = new Array([3,3,4,3,0,3,3,3,3,3,3,0]);
var pac2Row10:Array = new Array([0,3,3,3,0,3,4,3,3,3,3,0]);
var pac2Row11:Array = new Array([0,0,0,0,0,3,3,4,4,3,3,0]);
var pac2Row12:Array = new Array([0,0,0,0,0,0,3,3,3,3,0,0]);

pacLvl2[0].push(pac2Row1, pac2Row2, pac2Row3, pac2Row4, pac2Row5, pac2Row6, pac2Row7, pac2Row8, pac2Row9, pac2Row10, pac2Row11, pac2Row12);

var redOrange:int = 3;
var black:int = 4;

for (var k2 in pacLvl2[0])
{
	for (var i2 in pacLvl2[0][k2][0])
	{
		if (pacLvl2[0][k2][0][i2] == redOrange)
		{
			var block3:redOrangeBlock = new redOrangeBlock();
			block3.x = (i2 * (blockWidth)) + 210;
			block3.y = (k2 * (blockHeight)) + 50;
			addChild(block3);
		}
		else if (pacLvl2[0][k2][0][i2] == black)
		{
			var block4:blackBlock = new blackBlock();
			block4.x = (i2 * (blockWidth)) + 210;
			block4.y = (k2 * (blockHeight)) + 50;
			addChild(block4);
		}
	}
}

var pacBallSpeedX2:Number = 5;
var pacBallSpeedY2:Number = 5;

stage.addEventListener(Event.ENTER_FRAME, pacBallFly2);

function pacBallFly2(event:Event):void
{
	pacBall2.y -= pacBallSpeedY2;
	pacBall2.x += pacBallSpeedX2;
	if (pacBall2.hitTestObject(pacRight))
	{
		pacBall2.x = 620;
		pacBallSpeedX2 *= -1;
	}
	if (pacBall2.hitTestObject(pacTop))
	{
		pacBall2.y = 20;
		pacBallSpeedY2 *= -1;
	}
	if (pacBall2.hitTestObject(pacLeft))
	{
		pacBall2.x = 20;
		pacBallSpeedX2 *= -1;
	}
	if (pacBall2.hitTestObject(pacPaddle2))
	{
		pacBallAngle2();
	}
	if (pacBall2.hitTestObject(pacBottom))
	{
		pacBallSpeedY2 *= -1;
		pacBall2.x = 320;
		pacBall2.y = 480;
		balls --;
		if (balls == 0)
		{
			stage.removeEventListener(Event.ENTER_FRAME, pacBallFly2);
			stage.removeEventListener(Event.ENTER_FRAME, movement2);
			stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeys2);
			stage.removeEventListener(KeyboardEvent.KEY_UP, keyUps2);
			gameOver2 = true;
			gotoAndStop('pacGameOver');
		}
	}
}

function pacBallAngle2():void
{
	var pacBallPosition:Number = pacBall2.x - pacPaddle2.x;
	var pacAnglePercent:Number = (pacBallPosition / (pacPaddle2.width - pacBall2.width));
	pacBallSpeedX2 = pacAnglePercent * 10;
	pacBallSpeedY2 *= -1;
}

stage.addEventListener(Event.ENTER_FRAME, checkLvl2)

function checkLvl2(e:Event):void
{
	if(blockAmt2 == 0)
	{
		gotoAndStop(3);
		stage.removeEventListener(Event.ENTER_FRAME, pacBallFly2);
		stage.removeEventListener(Event.ENTER_FRAME, movement2);
		stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeys2);
		stage.removeEventListener(KeyboardEvent.KEY_UP, keyUps2);
		removeEventListener(Event.ENTER_FRAME, checkLvl2)
	}
}

A few of the variables were defined in frame 1, which is why they're not here. If you need any more explanation or any more code, I'll post it.


17.

Happy

Topic: TypeError: Error #1009:

Posted: 05/21/09 03:38 PM

Forum: Flash

Once again, thanks for all the help, kiwi-kiwi!
After a little help from the Kongregate forum, I've finally fixed the problem, and thought you might like to know.

The main problem ended up being the placement of the two variables in the loop that creates the blocks. I had the variables, and then the if statements. All I had to do was move the first var into the first if statement, and the second var into the second if statement. Now it works, and I can finally move on! :)


18.

None

Topic: TypeError: Error #1009:

Posted: 05/17/09 07:39 PM

Forum: Flash

I put traces in "if(balls == 0)" in the main file, on the game over frame in the main file, and in "if(_root.gameOver)" in blueBlock.as. The only one that didn't output, was the one on the actual game over frame (which is where I remove all of the event listeners from frame 1), but I'm wondering if that's just because the debugger is stopping at the error before it can get there. Also, I just tried removing the event listeners in "if(balls == 0)" which a few minutes ago gave me another error, but now it's not. Still doesn't change the original error, though. At least I know all the blocks are being removed.

Here's the code from the game over frame (to make sure I'm doing it right ;) ), everything else is the same as last time:

stage.removeEventListener(Event.ENTER_FRAME, pacBallFly);
stage.removeEventListener(Event.ENTER_FRAME, movement);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, checkKeys);
stage.removeEventListener(KeyboardEvent.KEY_UP, keyUps);
stop();

19.

None

Topic: TypeError: Error #1009:

Posted: 05/16/09 05:47 PM

Forum: Flash

Okay, we're getting closer. Putting "else if" there got rid of the "2007" error, but not the "1009" error. Interestingly, if I switch the two if statements, and add "else" to the second one, the "1009" error is gone, but the "2007" error is still there, and the blocks aren't cleared from the screen. If there was some way to do both at the same time, that would cool, but I'm not sure how that would work.


20.

None

Topic: TypeError: Error #1009:

Posted: 05/16/09 02:19 PM

Forum: Flash

Got your PM.

I had already removed all of the event listeners (pacBallFly, movement, checkKeys, and keyUps) in the game over frame. Just to see if it would work, I also tried removing them in the first frame (in the code that says to go to the game over frame when balls = 0), and in blueBlock.as (in the "if(_root.gameOver)" code) using both "stage" and "_root" in front, neither of which worked. The only event listener in the code that never gets removed is "beginClass," in blueBlock.as, but it didn't seem to do anything when I tried removing it. I'm out of ideas.


21.

Sad

Topic: TypeError: Error #1009:

Posted: 05/15/09 04:44 PM

Forum: Flash

Okay, I added the "next level" and "game over" code. When I go to the next level, everything's fine, but when I get a game over, I get two errors:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at blueBlock/enterFrameEvents()

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

If I dismiss the errors in Flash Player, it ends up doing what it's supposed to, but I'd like to get those cleared up. Even the guy who wrote one of the tutorials I'm using mentioned that the game over code brings up an error, but he did nothing to fix it.

Not much different from last time, but here's the rest of the code:

blueBlock.as:

package
{
	import flash.display.*;
	import flash.events.*;
	
	public class blueBlock extends MovieClip
	{
		public static var _root:MovieClip;
		public function blueBlock()
		{
			addEventListener(Event.ADDED, beginClass);
			addEventListener(Event.ENTER_FRAME, enterFrameEvents);
		}
		private function beginClass(event:Event):void
		{
			_root = MovieClip(root);
			_root.blockAmt ++;
		}
		private function enterFrameEvents(event:Event):void
		{
			if(_root.gameOver)
			{
				this.parent.removeChild(this);
				removeEventListener(Event.ENTER_FRAME, enterFrameEvents);
			}
//			trace("hello world");
			if (this.hitTestObject(_root.pacBall))
			{
				_root.pacBallSpeedY *= -1;
				if ((_root.pacBall.x >= (x +10)) || (_root.pacBall.x <= (x -10)))
				{
					_root.pacBallSpeedY *= -1;
					_root.pacBallSpeedX *= -1;
				}
				this.parent.removeChild(this);
				_root.blockAmt --;
				removeEventListener(Event.ENTER_FRAME, enterFrameEvents);
			}
		}
	}
}

Main Flash file:

stop();
import blueBlock;
import lavenderBlock;
var varRight:Boolean = false;
var varLeft:Boolean = false;
var xspeed:Number = 10;
var blockAmt:int = 0;
var gameOver:Boolean = false;

function checkKeys(event:KeyboardEvent):void
{
	if (event.keyCode == 39)
	{
		varRight = true;
	}
	if (event.keyCode == 37)
	{
		varLeft = true;
	}
}
function keyUps(event:KeyboardEvent):void
{
	if (event.keyCode == 39)
	{
		event.keyCode = 0;
		varRight = false;
	}
	if (event.keyCode == 37)
	{
		event.keyCode = 0;
		varLeft = false;
	}
}
function movement(Event):void
{
	if (varRight == true)
	{
		pacPaddle.x += xspeed;
	}
	if (varLeft == true)
	{
		pacPaddle.x -= xspeed;
	}
	if (pacPaddle.hitTestObject(pacLeft))
	{
		pacPaddle.x += xspeed;
	}
	if (pacPaddle.hitTestObject(pacRight))
	{
		pacPaddle.x -= xspeed;
	}
}
stage.addEventListener(Event.ENTER_FRAME, movement);
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeys);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUps);

var pacLvl1:Array = new Array();
pacLvl1.push(new Array());
var pac1Row1:Array = new Array([0,0,0,0,0,1,1,1,1,0,0,0,0,0]);
var pac1Row2:Array = new Array([0,0,0,1,1,1,1,1,1,1,1,0,0,0]);
var pac1Row3:Array = new Array([0,0,1,1,1,1,1,1,1,1,1,1,0,0]);
var pac1Row4:Array = new Array([0,1,1,1,1,1,1,1,1,1,1,1,1,0]);
var pac1Row5:Array = new Array([0,1,1,1,2,2,1,1,2,2,1,1,1,0]);
var pac1Row6:Array = new Array([0,1,1,1,2,2,1,1,2,2,1,1,1,0]);
var pac1Row7:Array = new Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
var pac1Row8:Array = new Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
var pac1Row9:Array = new Array([1,1,2,2,1,1,2,2,1,1,2,2,1,1]);
var pac1Row10:Array = new Array([1,2,1,1,2,2,1,1,2,2,1,1,2,1]);
var pac1Row11:Array = new Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
var pac1Row12:Array = new Array([1,1,0,1,1,1,0,0,1,1,1,0,1,1]);
var pac1Row13:Array = new Array([1,0,0,0,1,1,0,0,1,1,0,0,0,1]);

pacLvl1[0].push(pac1Row1, pac1Row2, pac1Row3, pac1Row4, pac1Row5, pac1Row6, pac1Row7, pac1Row8, pac1Row9, pac1Row10, pac1Row11, pac1Row12, pac1Row13);

var blue:int = 1;
var lavender:int = 2;

var blockWidth:int = 20;
var blockHeight:int = 20;

for (var k in pacLvl1[0])
{
	for (var i in pacLvl1[0][k][0])
	{
		var block:blueBlock = new blueBlock();
		var block2:lavenderBlock = new lavenderBlock();
		if (pacLvl1[0][k][0][i] == blue)
		{
			block.x = (i * (blockWidth)) + 190;
			block.y = (k * (blockHeight)) + 50;
			addChild(block);
		}
		else if (pacLvl1[0][k][0][i] == lavender)
		{
				
			block2.x = (i * (blockWidth)) + 190;
			block2.y = (k * (blockHeight)) + 50;
			addChild(block2);
		}
	}
}

var pacBallSpeedX:Number = 5;
var pacBallSpeedY:Number = 5;
var balls:int = 3;

stage.addEventListener(Event.ENTER_FRAME, pacBallFly);

function pacBallFly(Event):void
{
	pacBall.y -= pacBallSpeedY;
	pacBall.x += pacBallSpeedX;
	if (pacBall.hitTestObject(pacRight))
	{
		pacBall.x = 620;
		pacBallSpeedX *= -1;
	}
	if (pacBall.hitTestObject(pacTop))
	{
		pacBall.y = 20;
		pacBallSpeedY *= -1;
	}
	if (pacBall.hitTestObject(pacLeft))
	{
		pacBall.x = 20;
		pacBallSpeedX *= -1;
	}
	if (pacBall.hitTestObject(pacPaddle))
	{
		pacBallAngle();
	}
	if (pacBall.hitTestObject(pacBottom))
	{
		pacBallSpeedY *= -1;
		pacBall.x = 320;
		pacBall.y = 480;
		balls --;
		if (balls == 0)
		{
			gameOver = true;
			gotoAndStop('pacGameOver');
		}
	}
}

function pacBallAngle():void
{
	var pacBallPosition:Number = pacBall.x - pacPaddle.x;
	var pacAnglePercent:Number = (pacBallPosition / (pacPaddle.width - pacBall.width));
	pacBallSpeedX = pacAnglePercent * 10;
	pacBallSpeedY *= -1;
}

stage.addEventListener(Event.ENTER_FRAME, checkLvl)

function checkLvl(e:Event):void
{
	if(blockAmt == 0)
	{
		pacBall.x = 320;
		pacBall.y = 480;
		pacPaddle.x = 320
		gotoAndStop(2);
		removeEventListener(Event.ENTER_FRAME, checkLvl)
	}
}

Keep in mind, I'm still at the point where I need certain things explained in very simple and very specific terms, and that this is my second game, and first time using Classes (I probably should have mentioned that sooner). Thanks!


22.

None

Topic: TypeError: Error #1009:

Posted: 05/13/09 01:32 AM

Forum: Flash

Alright, progress.
First of all, the trace worked. I removed the redundant code in the if statements, moved the removeChild and removeEventListener to the end of the if statement, and changed _root to a public static var. This got rid of the error. The only thing I get now is a "Parameter hitTestObject must be non-null" when I get a game over, but that's probably because I haven't added the code for removing all of the remaining blocks from the screen when it goes to the game over frame. If there's anything else, I'll post it here.

Thanks for the help! :)


23.

Sad

Topic: TypeError: Error #1009:

Posted: 05/11/09 07:16 PM

Forum: Flash

At 5/11/09 03:24 PM, Sun-and-Moon wrote: I think it's because you tried to access the class lavenderBlock without defining it the same way you did blueBlock?

The error is pointing to blueBlock, and lavenderBlock isn't even being factored in yet. I know some of the code for lavenderBlock is different than code for blueBlock, but that will be changed later, when this error is gone. Any more ideas? Thanks anyway :)


24.

Sad

Topic: TypeError: Error #1009:

Posted: 05/11/09 07:12 PM

Forum: Flash

At 5/11/09 03:16 PM, kiwi-kiwi wrote: You could try putting

addEventListener(Event.ENTER_FRAME, enterFrameEvents);

in the event.added listener

I changed ENTER_FRAME to ADDED, which got rid of the error, but also made the blocks no longer breakable, so that's not it. If that's not what you meant, can you elaborate a little? I'm still new a this.


25.

Sad

Topic: TypeError: Error #1009:

Posted: 05/11/09 02:57 PM

Forum: Flash

I got this error in my flash, and don't know how to fix it:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at blueBlock/enterFrameEvents()

I'm making a breakout game in AS3. "blueBlock" in the error is a separate .as file being imported into my main file. At first the error wasn't a problem, because the game still played fine when exported. As soon as I made another .as file for the next different colored block, I wasn't able to test at all without exporting.

Here's the code for the .as file:

package
{
	import flash.display.*;
	import flash.events.*;

	public class blueBlock extends MovieClip
	{
		private var _root:MovieClip;
		public function blueBlock()
		{
			addEventListener(Event.ADDED, beginClass);
			addEventListener(Event.ENTER_FRAME, enterFrameEvents);
		}
		private function beginClass(event:Event):void
		{
			_root = MovieClip(root);
		}
		private function enterFrameEvents(event:Event):void
		{
			if (this.hitTestObject(_root.pacBall))
			{
				_root.pacBallSpeedY *= -1;
				this.parent.removeChild(this);
				removeEventListener(Event.ENTER_FRAME, enterFrameEvents);
				if ((_root.pacBall.x >= (x +9)) || (_root.pacBall.x <= (x -9)))
				{
					_root.pacBallSpeedY *= -1;
					_root.pacBallSpeedX *= -1;
					this.parent.removeChild(this);
					removeEventListener(Event.ENTER_FRAME, enterFrameEvents);
				}
			}
		}
	}
}

Here's the code for my main file:

stop();
import blueBlock;
var varRight:Boolean = false;
var varLeft:Boolean = false;
var xspeed:Number = 10;

function checkKeys(event:KeyboardEvent):void
{
	if (event.keyCode == 39)
	{
		varRight = true;
	}
	if (event.keyCode == 37)
	{
		varLeft = true;
	}
}
function keyUps(event:KeyboardEvent):void
{
	if (event.keyCode == 39)
	{
		event.keyCode = 0;
		varRight = false;
	}
	if (event.keyCode == 37)
	{
		event.keyCode = 0;
		varLeft = false;
	}
}
function movement(Event):void
{
	if (varRight == true)
	{
		pacPaddle.x += xspeed;
	}
	if (varLeft == true)
	{
		pacPaddle.x -= xspeed;
	}
	if (pacPaddle.hitTestObject(pacLeft))
	{
		pacPaddle.x += xspeed;
	}
	if (pacPaddle.hitTestObject(pacRight))
	{
		pacPaddle.x -= xspeed;
	}
}
stage.addEventListener(Event.ENTER_FRAME, movement);
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeys);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUps);

var pacLvl1:Array = new Array();
pacLvl1.push(new Array());
var pac1Row1:Array = new Array([0,0,0,0,0,1,1,1,1,0,0,0,0,0]);
var pac1Row2:Array = new Array([0,0,0,1,1,1,1,1,1,1,1,0,0,0]);
var pac1Row3:Array = new Array([0,0,1,1,1,1,1,1,1,1,1,1,0,0]);
var pac1Row4:Array = new Array([0,1,1,1,1,1,1,1,1,1,1,1,1,0]);
var pac1Row5:Array = new Array([0,1,1,1,2,2,1,1,2,2,1,1,1,0]);
var pac1Row6:Array = new Array([0,1,1,1,2,2,1,1,2,2,1,1,1,0]);
var pac1Row7:Array = new Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
var pac1Row8:Array = new Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
var pac1Row9:Array = new Array([1,1,2,2,1,1,2,2,1,1,2,2,1,1]);
var pac1Row10:Array = new Array([1,2,1,1,2,2,1,1,2,2,1,1,2,1]);
var pac1Row11:Array = new Array([1,1,1,1,1,1,1,1,1,1,1,1,1,1]);
var pac1Row12:Array = new Array([1,1,0,1,1,1,0,0,1,1,1,0,1,1]);
var pac1Row13:Array = new Array([1,0,0,0,1,1,0,0,1,1,0,0,0,1]);

pacLvl1[0].push(pac1Row1, pac1Row2, pac1Row3, pac1Row4, pac1Row5, pac1Row6, pac1Row7, pac1Row8, pac1Row9, pac1Row10, pac1Row11, pac1Row12, pac1Row13);

var blue:int = 1;
var lavender:int = 2;

var blockWidth:int = 20;
var blockHeight:int = 20;

for (var k in pacLvl1[0])
{
	for (var i in pacLvl1[0][k][0])
	{
		var block:blueBlock = new blueBlock();
		var block2:MovieClip = new lavenderBlock();
		if (pacLvl1[0][k][0][i] == blue)
		{
			block.x = (i * (blockWidth)) + 180;
			block.y = (k * (blockHeight)) + 40;
			addChild(block);
		}
		else if (pacLvl1[0][k][0][i] == lavender)
		{
				
			block2.x = (i * (blockWidth)) + 180;
			block2.y = (k * (blockHeight)) + 40;
			addChild(block2);
		}
	}
}

var pacBallSpeedX:Number = 5;
var pacBallSpeedY:Number = 5;
var balls:int = 3;

stage.addEventListener(Event.ENTER_FRAME, pacBallFly);

function pacBallFly(Event):void
{
	pacBall.y -= pacBallSpeedY;
	pacBall.x += pacBallSpeedX;
	if (pacBall.hitTestObject(pacRight))
	{
		pacBall.x = 620;
		pacBallSpeedX *= -1;
	}
	if (pacBall.hitTestObject(pacTop))
	{
		pacBall.y = 20;
		pacBallSpeedY *= -1;
	}
	if (pacBall.hitTestObject(pacLeft))
	{
		pacBall.x = 20;
		pacBallSpeedX *= -1;
	}
	if (pacBall.hitTestObject(pacPaddle))
	{
		pacBallAngle();
	}
	if (pacBall.hitTestObject(pacBottom))
	{
		pacBallSpeedY *= -1;
		pacBall.x = 320;
		pacBall.y = 480;
		balls --;
		if (balls == 0)
		{
			gotoAndStop('pacGameOver');
		}
	}
}

function pacBallAngle():void
{
	var pacBallPosition:Number = pacBall.x - pacPaddle.x;
	var pacAnglePercent:Number = (pacBallPosition / (pacPaddle.width - pacBall.width));
	pacBallSpeedX = pacAnglePercent * 10;
	pacBallSpeedY *= -1;
}

Lastly, I used both of these tutorials and put them together before tweaking them to fit my needs:
http://www.mrsunstudios.com/2008/07/tuto rial-create-a-brick-breaker-game-in-as3/

http://flashdevz.wordpress.com/2008/08/2 7/as3-pathfinding-part-1-understanding-2 d-arrays/

Thanks! :)


26.

None

Topic: quick question about error

Posted: 05/08/09 04:58 PM

Forum: Flash

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at blueBlock/enterFrameEvents()

It's probably because I took elements from two different tutorials, modifying them to fit my needs. I just don't know how to fix it. "blueBlock" is a separate .as file that's imported into my main file. The weird thing is that is says the error is in "blueBlock," but the code is identical to the code from one of the tutorials, so I would think the problem would have to be in my main code (the part I modified with parts of another tutorial).

I can post links to the tutorials I used, as well as my code if needed. Still, since the flash works fine anyway, it's not that big a deal.


27.

None

Topic: quick question about error

Posted: 05/08/09 12:01 AM

Forum: Flash

I got an error message when I tested my game inside Flash, but The game plays perfectly fine when exported. Should I even bother trying to figure out how to fix the error? Thanks!


28.

None

Topic: AS3 Breakout game help

Posted: 03/31/09 02:31 AM

Forum: Flash

Thanks everyone! I got it figured out, and it was much easier than I thought it would be. :)


29.

Sad

Topic: AS3 Breakout game help

Posted: 03/30/09 05:12 PM

Forum: Flash

I'm making a breakout-style game in AS3, and I need some help. I can make the ball bounce off the walls, ceiling, and paddle. When the ball hits any of the blocks, though, it only bounces on the Y-axis. That's fine when it hits the top or bottom of a block, but when it hits the side of a block, it might take out a whole two rows of blocks.

How can I get the ball to change it's X-axis trajectory when it hits the side of a block as opposed to the top or bottom of a block? Thanks in advance.


All times are Eastern Standard Time (GMT -5) | Current Time: 12:55 AM

<< < > >>

Viewing 1-30 of 31 matches. 1 | 2