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 › Actionscript code translation to Processing
Page Index Toggle Pages: 1
Actionscript code translation to Processing (Read 1116 times)
Actionscript code translation to Processing
Sep 23rd, 2009, 2:32pm
 
Hi, I am folloqing the Verlet tutorials from a Actionscript book, and I want to use that code in Processing, but I am having problems trying to translate the code with the getters and setters

So here is the AS3 code:
Code:
function set vx(value:Number):void {
 _oldX = x - value;
}

function get vx():Number {
 return x - _oldX;
}

I try different approach and fail, any suggestions?

I am already looking into toxi physics lib, but I still need to follow the book to understand what is going on under the hood Wink

Thanks
rS
Re: Actionscript code translation to Processing
Reply #1 - Sep 23rd, 2009, 3:22pm
 
did you check out the Comparison Page between p5 and AS ?
http://processing.org/learning/compare/actionscript.html
Re: Actionscript code translation to Processing
Reply #2 - Sep 24th, 2009, 1:06am
 
Hi Cedric, yes I saw that page but didn't help, as far as I can tell there is no native getters and setter methods in Processing, but there must be a way to work around that

I am working with getVX and setVX, but is not the same, and following the book with those methods is very confusing, and the results are not the same

Cheers
rS
Re: Actionscript code translation to Processing
Reply #3 - Sep 24th, 2009, 1:27am
 
Untested, but surely it's just a matter of writing your own getter and setter methods in your class declaration - I don't think you need to expressly define them as setter/getter methods.  i.e. in your class:

Code:
void setVX(int value) {
 _oldX = x - value;
}

int getVX() {
 return x - _oldX;
}


I'm at work so don't have time to test this properly, so my syntax might be all over the place (I'm switching around from too many languages at the moment!), but I'm fairly confident the concept is sound...
Re: Actionscript code translation to Processing
Reply #4 - Sep 24th, 2009, 5:23am
 
I can confirm that if you want getter and setter methods you can simply write them yourself in your class declaration.  I suspect that the only difference with ActionScript being that the latter expects you to expressly declare that they are getter and setter methods using the 'get' and 'set' keywords before the method/function name.  My guess is that this is required so the compiler can check that they are correctly formed - i.e. that the set method contains a parameter and the get method returns a value...

By default Processing lets you access properties directly i.e. myObject.property so you don't really have to define these methods.  If you want to restrict direct access to properties you'll need to make them private in your class declaration.  I must admit I haven't fully understood the benefit of doing this, but it is meant to be better practice...  probably because you can include validation in your getter/setter methods to ensure properties are set to acceptable values/types.  I'd assume that's most likely to be useful when others write sub-classes based on your class...
Page Index Toggle Pages: 1