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 › javascript exception
Page Index Toggle Pages: 1
javascript exception (Read 1953 times)
javascript exception
Jul 23rd, 2007, 4:47pm
 
Hi all,

I need to call a javascript function from processing, everytime I rollover a button. If I use normal buttons from a library (Interfascia)it works with no problem when I click on a button, but since I don't need normal buttons and I need rollover, using this is not optimal. If I use a simple button class it executes the function on th first rollover and then it blocks the applet throwing me this in the java console:

Error while running applet.
java.lang.ClassCastException: java.lang.String cannot be cast to netscape.javascript.JSObject
     at AC_buttonsOver.update(AC_buttonsOver.java:87)
     at AC_buttonsOver.draw(AC_buttonsOver.java:57)
     at processing.core.PApplet.handleDisplay(PApplet.java:1355)
     at processing.core.PGraphics.requestDisplay(PGraphics.java:564)
     at processing.core.PApplet.run(PApplet.java:1450)
     at java.lang.Thread.run(Unknown Source)
java.lang.ClassCastException: java.lang.String cannot be cast to netscape.javascript.JSObject
     at AC_buttonsOver.update(AC_buttonsOver.java:87)
     at AC_buttonsOver.draw(AC_buttonsOver.java:57)
     at processing.core.PApplet.handleDisplay(PApplet.java:1355)
     at processing.core.PGraphics.requestDisplay(PGraphics.java:564)
     at processing.core.PApplet.run(PApplet.java:1450)
     at java.lang.Thread.run(Unknown Source)


Does someone have an idea of what's the problem, is there some walkthrough?
Re: javascript exception
Reply #1 - Jul 23rd, 2007, 5:04pm
 
This is the actual Processing code I'm testing:

http://chronos.zkm.de/~luis/tests/sketcher.html
(the html containing the applet and linking to the .js)

http://chronos.zkm.de/~luis/tests/applet/

(just the applet)

I appreciate any help since my experience with this Live Connect started yesterday and is blocking me completely...
Thanks
Re: javascript exception
Reply #2 - Jul 27th, 2007, 9:46am
 
just call it like this:

Code:

JSObject.getWindow(this).eval( "alert(\"Processing says hello.\")" );


working example (including an alternative way):
http://florianjenett.de/processing/sketchbook/callingjs/index.html

F
Re: javascript exception
Reply #3 - Jul 28th, 2007, 4:41pm
 
Thanks Fjen, exactly what I needed. Now I have an issue with mysql, published in this part of the forums:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=LibraryProblems;action=display;num=1185470339

Someone has told me that I need to "sign" my applet if I want to overcome security issues, but nonetheless you say in the mySQL library docs, that it is only necessary if you're out of localhost...can you give some input perhaps?

Thanks,

P
Re: javascript exception
Reply #4 - Jul 28th, 2007, 5:49pm
 
Another small question...when used within a subclass, the getWindow()method throws an exception:
Semantic Error: No applicable overload for a method with signature "getWindow(evolvingCSS_stage3_3.f)"
what parameter should I use instead of(this)?

thx a lot
Re: javascript exception
Reply #5 - Jul 29th, 2007, 2:03am
 
that's a tricky issue, the short answer is to structure things such that you aren't using 'this' from another tab. you can have your tab call a function in the main tab that uses 'this' to get the window properly and pass it back.
Re: javascript exception
Reply #6 - Jul 29th, 2007, 8:20am
 
... and in case of a subclass just pass an instance of papplet upon initialization into the object:

Code:

MyClass test;

void setup()
{
test = new MyClass( this );
test.doSmthng();
}

class MyClass {
PApplet papplet;
MyClass ( PApplet _p )
{
papplet = _p;
}

void doSmthng () {
papplet.println("called from within "+this.getClass().getName());
}
}


F
Re: javascript exception
Reply #7 - Jul 29th, 2007, 3:42pm
 
Thanks...yes indeed, I discovered the papplet class just a bit before, nonetheless I declared it as a global variable and it's working. If I get trouble I'll use the instantiation version...
Page Index Toggle Pages: 1