Removing All Entities on a World


(Noah) #1

I’m trying to remove all entities from a world when a function is called.

Here is the code:

package  {

import net.flashpunk.World;
import net.flashpunk.utils.Input;
import net.flashpunk.utils.Key;
import net.flashpunk.FP;


public class MainScreen extends World{
	
	var scene:Number = 1;
	var sceneType:Number = 1;
	/*
		1 = Straight Forward Text
		2 = Can't move Forward (Choice to make)
	*/

	public function MainScreen() {
		loadScene();
	}
	
	public function loadScene()
	{
		FP.MainScreen.removeAll;
		
		add (new Background('test'));
		add (new Character(5, 250, 'Beta'));
		add (new Character(400, 200, 'Sanic'));
		add (new Textbox(0, 450));
		add (new DialogTextLine1(10, 455, "Random Text"));
	}
	
	public function changeScene():void
	{
			scene += 1;
			loadScene();
	}
	
	override public function update():void
	{
		if (Input.released (Key.SPACE))
		{
			changeScene();
		}
	}
	

}

}

Can someone tell me what I am doing wrong?


(Jacob Albano) #2

MainScreen isn’t a variable on FP, so that should be giving you a compile error, unless you modified the class yourself, which I wouldn’t recommend.

The other problem is that you’re not calling the function, just referencing it. You should be getting a compile warning about that. You need to add the parentheses after it in order for it to have any effect.

// this
world.removeAll();

// not this
world.removeAll;

(Noah) #3

/Users/zazorah/Desktop/My Stuff/Flash Stuff/Games/Sanic Dating Sim/MainScreen.as, Line 24 1120: Access of undefined property world.

This is the error I keep getting.

I tried putting your line of code in and I still get it.


(Jacob Albano) #4

Wut? Mine is example code. Obviously you should replace world with the name of your own world variable.


(Noah) #5

ok now I get this

/Users/zazorah/Desktop/My Stuff/Flash Stuff/Games/Sanic Dating Sim/MainScreen.as, Line 24	1061: Call to a possibly undefined method removeAll through a reference with static type Class.

sorry for the trouble. I’m kinda still a noob at this.


(Jacob Albano) #6

No problem. :wink:

It would help to see the line of code that’s causing the error, but I can guess what the problem is here. You’re probably doing something like this:

MainScreen.removeAll();

You’ve got to call that method on the instance of MainScreen, not the class itself. In this case, since your code is inside MainScreen anyway, you don’t have to specify it at all:

removeAll();
// or
this.removeAll();

(Noah) #7

THANK YOU SO MUCH!

That worked perfectly :smile: