We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › flash convert, Dynamic reference.
Page Index Toggle Pages: 1
flash convert, Dynamic reference. (Read 386 times)
flash convert, Dynamic reference.
Mar 17th, 2006, 6:23pm
 
Hi i'm new to processing and need some guidance.
I have created a class and made several instances of it.
In the draw function I want to call a function <.update()> from each one. In flash I have been able to put this in a for loop and used what I think is called array access notation to reference the instances.
Example code

MyClass obj0 = new Myclass();
MyClass obj1 = new Myclass();
MyClass obj2 = new Myclass();

void draw() {
 for(int i = 0; i < 3; i++) {
   this["obj" + i].update();
 }
}

How would i do this in processing? The code above wont run, i have tried replacing this[...] with MyClass[...] but that’s it i’m out of ideas.
Any suggestions?

//technograph
Re: flash convert, Dynamic reference.
Reply #1 - Mar 18th, 2006, 10:06am
 
this should work:
Code:

MyClass[] obj=new MyClass[3];
void setup(){
for(int i = 0; i < 3; i++) {
obj[i]=new MyClass();
}
}
void draw(){
for(int i = 0; i < 3; i++) {
obj[i].update();
}
}


You must create a new array of objects of the MyClass class. At the setup methode you fill this array with three new objects.
Page Index Toggle Pages: 1