Search Results

Search found 2 results on 1 pages for 'phpscriptcoder'.

Page 1/1 | 1 

  • Using same onmouseover function for multiple objects

    - by phpscriptcoder
    I'm creating a building game in JavaScript and PHP that involves a grid. Each square in the grid is a div, with an own onmouseover and onmousedown function: for(x=0; x < width; x++) { for(y=0; y < height; y++) { var div = document.createElement("div"); //... div.onmouseclick = function() {blockClick(x, y)} div.onmouseover = function() {blockMouseover(x, y)} game.appendChild(div); } } But, all of the squares seem to have the x and y of the last square that was added. I can sort of see why this is happening - it is making a pointer to x and y instead of cloning the variables - but how could I fix it? I even tried for(x=0; x < width; x++) { for(y=0; y < height; y++) { var div = document.createElement("div"); var myX = x; var myY = y; div.onmouseclick = function() {blockClick(myX, myY)} div.onmouseover = function() {blockMouseover(myX, myY)} game.appendChild(div); } } with the same result. I was using div.setAttribute("onmouseover", ...) which worked in Firefox, but not IE. Thanks!

    Read the article

  • Is this the right way to write a ProtocolDecoder in MINA?

    - by phpscriptcoder
    public class CustomProtocolDecoder extends CumulativeProtocolDecoder{ byte currentCmd = -1; int currentSize = -1; boolean isFirst = false; @Override protected boolean doDecode(IoSession is, ByteBuffer bb, ProtocolDecoderOutput pdo) throws Exception { if(currentCmd == -1) { currentCmd = bb.get(); currentSize = Packet.getSize(currentCmd); isFirst = true; } while(bb.remaining() > 0) { if(!isFirst) { currentCmd = bb.get(); currentSize = Packet.getSize(currentCmd); } else isFirst = false; //System.err.println(currentCmd + " " + bb.remaining() + " " + currentSize); if(bb.remaining() >= currentSize - 1) { Packet p = PacketDecoder.decodePacket(bb, currentCmd); pdo.write(p); } else { bb.flip(); return false; } } if(bb.remaining() == 0) return true; else return false; } } Anyone see anything wrong with this code? When a lot of packets are received at once, even when only one client is connected, one of them might get cut off at the end (12 bytes instead of 15 bytes, for example) which is obviously bad.

    Read the article

1