eventHandling : mouse Coods

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

eventHandling : mouse Coods

Clément Bera
Hey,

In javascript I used to do :

myCanvas.addEventListener('mousemove', mouseCheck, false);
function mouseCheck(e){
    var x, y;
    x = e.pageX;
    y = e.pageY;
    //something...
}
and this way I had the coods of the mouse in my function.

How can I do this in Amber ?

I may use TagBrush>>onMouseMove: but how can I get the mouse coods ?

Thanks,
Reply | Threaded
Open this post in threaded view
|

Re: eventHandling : mouse Coods

Nicolas Petton
Hi!

You can do: (I didn't test it)

myCanvas addEventListener: 'mousemove' do: [:e |
    | x y |
    x = e pageX.
    y = e pageY.
    "Something"
]

If you want to extract the callback, then I would do something like:

myCanvas addEventListener: 'mousemove' do: [ :e | self mouseCheck: e ]

mouseMove: anEvent
    | x y |
    x = anEvent pageX.
    y = anEvent pageY.
    "Something"


Cheers,
Nico


2012/7/4 Farine <[hidden email]>
Hey,

In javascript I used to do :

myCanvas.addEventListener('mousemove', mouseCheck, false);
function mouseCheck(e){
    var x, y;
    x = e.pageX;
    y = e.pageY;
    //something...
}
and this way I had the coods of the mouse in my function.

How can I do this in Amber ?

I may use TagBrush>>onMouseMove: but how can I get the mouse coods ?

Thanks,

Reply | Threaded
Open this post in threaded view
|

Re: eventHandling : mouse Coods

Clément Bera
Ok thanks it works

On Wednesday, July 4, 2012 2:12:04 PM UTC+2, nicolas petton wrote:
Hi!

You can do: (I didn't test it)

myCanvas addEventListener: 'mousemove' do: [:e |
    | x y |
    x = e pageX.
    y = e pageY.
    "Something"
]

If you want to extract the callback, then I would do something like:

myCanvas addEventListener: 'mousemove' do: [ :e | self mouseCheck: e ]

mouseMove: anEvent
    | x y |
    x = anEvent pageX.
    y = anEvent pageY.
    "Something"


Cheers,
Nico


2012/7/4 Farine <[hidden email]>
Hey,

In javascript I used to do :

myCanvas.addEventListener('mousemove', mouseCheck, false);
function mouseCheck(e){
    var x, y;
    x = e.pageX;
    y = e.pageY;
    //something...
}
and this way I had the coods of the mouse in my function.

How can I do this in Amber ?

I may use TagBrush>>onMouseMove: but how can I get the mouse coods ?

Thanks,

Reply | Threaded
Open this post in threaded view
|

Re: eventHandling : mouse Coods

Herby Vojčík
I don't know if it is not safer (from cross-browser PoV), since jQuery
is included with amber, to rather reuse jQuery bind to hook an event.

TagBrush should have asJQuery which could be used for this, if I am not
mistaken.

Herby

Farine wrote:

> Ok thanks it works
>
> On Wednesday, July 4, 2012 2:12:04 PM UTC+2, nicolas petton wrote:
>
>     Hi!
>
>     You can do: (I didn't test it)
>
>     myCanvas addEventListener: 'mousemove' do: [:e |
>     | x y |
>     x = e pageX.
>     y = e pageY.
>     "Something"
>     ]
>
>     If you want to extract the callback, then I would do something like:
>
>     myCanvas addEventListener: 'mousemove' do: [ :e | self mouseCheck: e ]
>
>     mouseMove: anEvent
>     | x y |
>     x = anEvent pageX.
>     y = anEvent pageY.
>     "Something"
>
>
>     Cheers,
>     Nico
>
>
>     2012/7/4 Farine <[hidden email] <mailto:[hidden email]>>
>
>         Hey,
>
>         In javascript I used to do :
>
>         myCanvas.addEventListener('mousemove',  mouseCheck,  false);
>
>         function mouseCheck(e){
>         var x, y;
>         x = e.pageX;
>         y = e.pageY;
>         //something...
>         }
>         and this way I had the coods of the mouse in my function.
>
>         How can I do this in Amber ?
>
>         I may use TagBrush>>onMouseMove: but how can I get the mouse coods ?
>
>         Thanks,
>
>
Reply | Threaded
Open this post in threaded view
|

Re: eventHandling : mouse Coods

Nicolas Petton
Right. That would probably be better :)

Nico

2012/7/4 Herby Vojčík <[hidden email]>
I don't know if it is not safer (from cross-browser PoV), since jQuery is included with amber, to rather reuse jQuery bind to hook an event.

TagBrush should have asJQuery which could be used for this, if I am not mistaken.

Herby

Farine wrote:
Ok thanks it works

On Wednesday, July 4, 2012 2:12:04 PM UTC+2, nicolas petton wrote:

    Hi!

    You can do: (I didn't test it)

    myCanvas addEventListener: 'mousemove' do: [:e |
    | x y |
    x = e pageX.
    y = e pageY.
    "Something"
    ]

    If you want to extract the callback, then I would do something like:

    myCanvas addEventListener: 'mousemove' do: [ :e | self mouseCheck: e ]

    mouseMove: anEvent
    | x y |
    x = anEvent pageX.
    y = anEvent pageY.
    "Something"


    Cheers,
    Nico


    2012/7/4 Farine <[hidden email] <mailto:[hidden email]>>


        Hey,

        In javascript I used to do :

        myCanvas.addEventListener('mousemove',  mouseCheck,  false);

        function mouseCheck(e){
        var x, y;
        x = e.pageX;
        y = e.pageY;
        //something...
        }
        and this way I had the coods of the mouse in my function.

        How can I do this in Amber ?

        I may use TagBrush>>onMouseMove: but how can I get the mouse coods ?

        Thanks,



Reply | Threaded
Open this post in threaded view
|

Re: eventHandling : mouse Coods

Clément Bera-2
In fact, I used TagBrush>>onClick.

My issue was I didn't know I could get the event by doing TagBrush onClick: [:event | "some code"]

Now it's ok.

Thanks,


2012/7/4 nicolas petton <[hidden email]>
Right. That would probably be better :)

Nico


2012/7/4 Herby Vojčík <[hidden email]>
I don't know if it is not safer (from cross-browser PoV), since jQuery is included with amber, to rather reuse jQuery bind to hook an event.

TagBrush should have asJQuery which could be used for this, if I am not mistaken.

Herby

Farine wrote:
Ok thanks it works

On Wednesday, July 4, 2012 2:12:04 PM UTC+2, nicolas petton wrote:

    Hi!

    You can do: (I didn't test it)

    myCanvas addEventListener: 'mousemove' do: [:e |
    | x y |
    x = e pageX.
    y = e pageY.
    "Something"
    ]

    If you want to extract the callback, then I would do something like:

    myCanvas addEventListener: 'mousemove' do: [ :e | self mouseCheck: e ]

    mouseMove: anEvent
    | x y |
    x = anEvent pageX.
    y = anEvent pageY.
    "Something"


    Cheers,
    Nico


    2012/7/4 Farine <[hidden email] <mailto:[hidden email]>>


        Hey,

        In javascript I used to do :

        myCanvas.addEventListener('mousemove',  mouseCheck,  false);

        function mouseCheck(e){
        var x, y;
        x = e.pageX;
        y = e.pageY;
        //something...
        }
        and this way I had the coods of the mouse in my function.

        How can I do this in Amber ?

        I may use TagBrush>>onMouseMove: but how can I get the mouse coods ?

        Thanks,






--
Clément Béra
Elève-ingénieur à l'Ecole des Mines de Douai