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 › Can I refrence a class like ActionScript
Page Index Toggle Pages: 1
Can I refrence a class like ActionScript? (Read 1010 times)
Can I refrence a class like ActionScript?
Mar 23rd, 2010, 2:29am
 
Hello,
I am pretty new to Processing but have some experience in ActionScript.
I am trying to make a fish like particle system that behaves as a school of fish.
I want to pass the instance of the manager class to a sub class so that the subclass can reference to a property of the main class. Below i show the structure:
mainAppilcationFile //like the document class in AS3
 |_fishManager1
 |_fishManager2 // the manager class with a property
   |_mainFish  //the instance of the main fish
   |_followFish // the class that wants to know the position of mainFish

basically i want the followFish to know where the mainFish is positioned. So i thought i pass in the reference to the manager class in the constructor of the follow fish like this followFish = new FollowFish(this);
the constructor of followFish looks like this:
void FollowFish(class pRoot)
{
 _parent = pRoot;
 _mainFishX = _parent.mainFish.x
}

this seems not to be working. When the manager class is at the top level (so the manager class is the "DocumentClass") it works (then i don't need the reference), but because i want to have multiple schools of fish i need to put the manager class a level down.

Thanks in advance!
Peter Goes
Re: Can I refrence a class like ActionScript?
Reply #1 - Mar 23rd, 2010, 6:17am
 
"Not working" is always vague...

I guess the issue is in the constructor declaration. I think it should look like:
Code:
void FollowFish(FishManager pRoot)
{
_parent = pRoot;
_mainFishX = _parent.mainFish.x
}

ie. you must indicate the exact type of the parent.
Re: Can I refrence a class like ActionScript?
Reply #2 - Mar 24th, 2010, 7:53am
 
like philho said.

I'd just like to add that, if the mainfish object is the only thing you want to reference, you can just reference that directly:

void FollowFish(MainFish m) {
_mainFishX=m;
}
Re: Can I refrence a class like ActionScript?
Reply #3 - Mar 30th, 2010, 6:59am
 
Thank you,

I come from an ActionScript background, so the direct reference that is used in processing seems a little strange.

But thanks!
Page Index Toggle Pages: 1