Problem with event.getX or Y

Questions, tips and tricks and techniques for scripting in Servoy

Problem with event.getX or Y

Postby irenem » Wed Nov 17, 2010 4:26 pm

I try to get the location of a field onSelection in the client Design Mode. I know that the location is x:0 and y:0 because I place it myself.

In the method onSelection(event):
Code: Select all
var x = event.getX()
var y = event.getY()
application.output(x + ' / '+ y)


If I run the debugger the event.data returns x and y as 0, but the application output returns random values as "75 / 199" or "39 / 92".

I also tried with event.data[0].getX() but it returns with an error.

what can I do to get the x and y from the data?
Irene Meyer

Version: 6.0.5
Java version 1.6.0_29
Mac OS X Version 10.7.3
User avatar
irenem
 
Posts: 279
Joined: Tue Aug 28, 2007 2:09 pm
Location: Netherlands

Re: Problem with event.getX or Y

Postby Karel Broer » Wed Nov 17, 2010 5:02 pm

Is it possible for you to update to the latest Java version for MacOS X?
I noticed you're using an older Java version (we're at 1.6.0_22 now).
Karel Broer
ServoyCamp - http://www.servoycamp.com
User avatar
Karel Broer
 
Posts: 779
Joined: Mon May 03, 2004 12:49 am
Location: Doetinchem

Re: Problem with event.getX or Y

Postby irenem » Wed Nov 17, 2010 5:21 pm

Hi Karel,
Thank you for reply.
I am using the latest version, I just forgot to update the signature. :oops:
Irene Meyer

Version: 6.0.5
Java version 1.6.0_29
Mac OS X Version 10.7.3
User avatar
irenem
 
Posts: 279
Joined: Tue Aug 28, 2007 2:09 pm
Location: Netherlands

Re: Problem with event.getX or Y

Postby jcompagner » Wed Nov 17, 2010 5:40 pm

event.getX() is the mouse position x not the element x.

to get the element x you should look "elements.myfield." (as an example)
there you see that to get x you have to do getLocationX();

so

event.data[0].getLocationX();
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Problem with event.getX or Y

Postby irenem » Wed Nov 17, 2010 5:54 pm

Thank you Johan.
It works.
Irene Meyer

Version: 6.0.5
Java version 1.6.0_29
Mac OS X Version 10.7.3
User avatar
irenem
 
Posts: 279
Joined: Tue Aug 28, 2007 2:09 pm
Location: Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 6 guests