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 & HelpOther Libraries › Objects and arrays, from JS to Processing.
Page Index Toggle Pages: 1
Objects and arrays, from JS to Processing. (Read 299 times)
Objects and arrays, from JS to Processing.
Feb 5th, 2009, 2:34am
 
How can I access objects and arrays from JavaScript space?
Can someone kindly post a working sketch?
Thanks.

Edit: I can access DOM elements but not the properties of JavaScript objects.

Suppose I have

foo = {"one":1,"two":2};

defined globally, when when I try to access "foo" from Processing via the window "JSObject" by using getMember(String <name>), I get a reference to an "Object". And I can't figure out how to get to "one" and "two" from this object.
Re: Objects and arrays, from JS to Processing.
Reply #1 - Feb 5th, 2009, 7:28am
 
A quick but semi messy quick fix is to have as many hidden input fields as variables you'll need(could work for arrays but would need string splitting).
Code:

<form>
<input id="var1" type="hidden" value="my variable here" />
<input id="var2" type="hidden" value="my other variable here"/>
</form>

Use javascript to change the value of it, from that you should be able to read from that(noting your edit) and work from their. I'll try to find a better solution tomorrow afternoon unless you get a real fix.
Re: Objects and arrays, from JS to Processing.
Reply #2 - Feb 5th, 2009, 12:15pm
 
jettlarue wrote on Feb 5th, 2009, 7:28am:
A quick but semi messy quick fix is to have as many hidden input fields as variables you'll need(could work for arrays but would need string splitting).
Code:

<form>
<input  id="var1" type="hidden" value="my variable here" />
<input  id="var2" type="hidden" value="my other variable here"/>
</form>

Use javascript to change the value of it, from that you should be able to read from that(noting your edit) and work from their. I'll try to find a better solution tomorrow afternoon unless you get a real fix.


Yes, I did think about something like that. Except that my version was a hidden table. And I was too embarassed to mention that in polite company LOL.

Tables would perhaps even map quite well to nested objects as well.

Sadly, no real solutions so far. :(
Page Index Toggle Pages: 1