0

Possible Duplicate:
jQuery and Prototype events

I am using the Box2dJS library, and it uses prototype, so I had to include the prototype library for it to work. I am not using any prototype code in my main script, only the Box2d objects use prototype. I am using JQuery in my script, and since I included prototype, it seems that the jQuery events aren't firing.

Here is the relevant JS code:

$.noConflict();

jQuery(document).ready(function(){
init();
});

function init(){

//add event handler to surrounding DIV to monitor mouse move and keystrokes
jQuery("#container").keypress(function(e){
    keys[e.keyCode] = true;
    alert("key pressed!");
});
jQuery("#container").keydown(function(e){
    keys[e.keyCode] = true;
});
jQuery("#container").keyup(function(e){
    keys[e.keyCode] = true;
    alert("Key released!");
});
}

And here is the html code:

<html>
<head>
    <title>Box2D Test</title>
    <!--[if IE]><script src="lib/excanvas.js"></script><![endif]-->
    <script src="lib/prototype-1.6.0.2.js"></script>
    <!-- box2djs scripts here-->
</head>
<body>
    <center>
        <div id="container" style="border:1px solid; cursor:none; width:600px; height:400px;">
            <canvas id="canvas" width="600" height="400" >
                Could not create Canvas!
            </canvas>
        </div>
        <script type="text/javascript" src="jquery-1.6.2.min.js"></script>
        <script src='js/box2dutils.js'></script>
        <script type="text/javascript" src="main.js"></script>
    </center>
</body>
</html>

None of the alerts are going off, but everything works a-ok when I remove the prototype (and the box2d) library. How can I fix this?

Community
  • 1
  • 1
Keelx
  • 907
  • 3
  • 17
  • 26
  • @Nicklas A. Not so. I am not trying to fire a prototype event from jQuery, I am trying to just use jQuery events. And besides, that question isn't even solved. – Keelx Jul 10 '11 at 22:06

2 Answers2

1

From the snippet of code you provided, you may want to re-order the loading of the box2dutils lib before the jQuery library. It could be that the box2dutils could be hijacking the events or causing conflicts with jQuery

Salman Paracha
  • 1,697
  • 2
  • 16
  • 27
  • impossible. The box2dutils is only filled with debug drawing utilities. Nothing else- I looked over it myself. I switched them to make sure anyway, nothing changed. – Keelx Jul 10 '11 at 22:03
0

It very likely that they are not compatible with each other, do you have to use both?

Nicklas A.
  • 6,501
  • 7
  • 40
  • 65
  • I could use full-on prototype, if I have to pick one or the other, because box2djs requires prototype. But then I would have to rewrite a lot of my code and learn a completely new api... – Keelx Jul 10 '11 at 22:11