00:00
00:00
Newgrounds Background Image Theme

Proximothegr81 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As2 Instance Name Problems

479 Views | 4 Replies
New Topic Respond to this Topic

As2 Instance Name Problems 2013-04-15 17:29:41


Okay, so I'm creating a side-scrolling game in AS2 using a tutorial for a guide, and in order to create a collision detection with the main mc, I give the mc an instance name. When I do that, though, if I test the movie, my character freezes and does not respond to any commands. Anyone know how to fix this? Much appreciated.

Response to As2 Instance Name Problems 2013-04-16 01:57:10


I think that could have something to do with the collision script you use.
Could you show the Tutorial you make?


I code Flash Games! Check out the Stealth Pervert and VOID

Response to As2 Instance Name Problems 2013-04-16 16:52:55


The tutorial is at kongregate.com/labs lesson 5.

My collision detection code is here though. (rabbit is the main mc)

class alien extends MovieClip
{
	var speed;
	
	function onLoad()
	{
		_x = 700;
		_y = 325;
		speed = Math.random()*2+5;
	}
	function onEnterFrame()
	{
		_x-=speed;
		if(_x< -100)
		{
			this.removeMovieClip();
		}
	if(this.hitTest(_root.rabbit))
	{
		die();
	}
	function die()
	{
		this.removeMovieClip();
	}
	}
}

I'm not sure if that helps at all, but I figured I'd give it to you anyway.

Response to As2 Instance Name Problems 2013-04-18 17:16:20


You can't remove a movie clip which has depth below 0. All preplaced movie clips initially have a depth of -16384.
So add to onLoad function:
[code]
swapDepths(_root.getNextHighestDepth());
[/code]
getNextHighestDepth() returns values >= 0, so it is an acceptable solution.

Also, does your code run fine with collision turned off?

Response to As2 Instance Name Problems 2013-04-22 16:46:03


Actually, I figured out the problem the other day. I had some misplaced brackets and the command was placed outside the onEnterFrame function.