This site requires JavaScript, please enable it in your browser!
Greenfoot back
jesusOrtaHdz
jesusOrtaHdz wrote ...

2013/10/23

How to acces a method of another class

jesusOrtaHdz jesusOrtaHdz

2013/10/23

#
Hey guys.. I need a little help.. How do I access to a method of another class?
danpost danpost

2013/10/23

#
The method (1) must be a 'public' method; and (2) it needs to be called on an object created from the class the method is in or a subclass of it. Also, the object must be typecast as an object of the class or a subclass of it. For example, if you had a Counter object that has an 'public void add(int)' method (and let us say that it the only Counter object in the world) then you could use:
// from the world class:
((Counter)getObjects(Counter.class).get(0)).add(5);
// from an actor class
((Counter)getWorld().getObjects(Counter.class).get(0)).add(5);
jesusOrtaHdz jesusOrtaHdz

2013/10/23

#
thanks for help me..
You need to login to post a reply.