Page 1 of 1
java getArg
Posted: 15 February 2013, 16:52
by cora89
hi,
i want to know in which square my player wants to put his token.
i have defined square_{X} in my .tpl page.
I want to have the X of the square where he wants to play.
Is it possible with getArg or must i find it from the (x,y) mouse position ?
thanks for your help.
Have a nice day.
Re: java getArg
Posted: 16 February 2013, 13:44
by Een
Hi,
When you set up your squares on the board, you give them an id based on your coordinates.
For example in Reversi :
Code: Select all
<div id="square_{X}_{Y}" class="square" style="left: {LEFT}px; top: {TOP}px;"></div>
Then in your JS you need to attach an onclick event to your squares, so that when clicked, a specific function is called:
Code: Select all
dojo.query( '.square' ).connect( 'onclick', this, 'onPlayDisc' );
Then when the method is called, you get the id of the square through the evt parameter (evt.currentTarget.id), and you can split it to get the coordinates.
Code: Select all
onPlayDisc: function( evt )
{
// Stop this event propagation
dojo.stopEvent( evt );
// Get the cliqued square x and y
// Note: square id format is "square_X_Y"
var coords = evt.currentTarget.id.split('_');
var x = coords[1];
var y = coords[2];
[...]
},
Then you can use it as you need (you can find more examples and information in the
Reversi tutorial).
Cheers,
Een
Re: java getArg
Posted: 17 February 2013, 09:23
by cora89
thx for you help ^^