What do I import for world.getClass() [Solved]


(Lozza JP) #1

Hi reading the tutorial at http://useflashpunk.net/intermediate/accessing-entities.html

But I can’t get it to work, I keep getting access of undefined property world.

I have tried importing the lot using net.flashpunk.* etc.

Am I missing something? I am sure I got this working before.


(Mike Evmm) #2

If your doing it from.inside an entity and wotld is null, the entityentity probably hasnt been added yet. Try putting your code on verridden added()


(Lozza JP) #3

Does added() run once after that entity has been added to the world???


(Lozza JP) #4

Also it is inside a data class, it doesn’t even extend Entity or anything (but it is working fine for other simple things, such as adding new blocks)


(Martí Angelats i Ribera) #5

added() is executed when you do add the entity to the world.

You should be extending something, otherwise it is probably wrong. In the ttutorial they extend Entity. If you don’t do this world doesn’t exist becouse is an Entity parameter.


(Lozza JP) #6

extended entity but still says world is undefined property.

It was in a static function,

now it is out of the static function it works… but I really want to use world.getClass inside my static function, is there a reason it has to be non static?


(Martí Angelats i Ribera) #7

It can’t be static becouse world isn’t an static property. Remove the static (static suff is usually unused in FP).


(Lozza JP) #8

Then how do I access stuff in my events class?

right now as a static function, any other class can just use Events.eventCall()

Do I have to instantiate Events somehow?


(Martí Angelats i Ribera) #9

If it’s an Event class you need to pass the entity wich is calling the action.

In the Events class

public static function doSomething(parameters, caller:Entity)
{
	caller.world.getClass; //etc.
}

and for the Entity calling this

Events.doSomething(parameters, this);

(Lozza JP) #10

yes, yes yes yes

Thank you again copying, always saving me!

Has fixed 2 of my recent posts in one short easy snippet!


(Mike Evmm) #11