Jump to content

Deleting div objects in Array


vytas
 Share

Recommended Posts

I have renders a div and then deletes it but that's the problem the div's aren't getting deleted but the array is storing the object this is the code.

<html><head><title>MOMSG</title><style type="text/css">div {font-family: verdana;font-size: 10px;text-align: center;}.wall {background-color: #EFEFEF;border-color: #DDDEDB;border-width: 1px;border-style: solid;position: absolute;height: 19px;width: 19px;}.safezone {background-color: #3CC02A;border-color: #000000;border-width: 0px;border-style: solid;position: absolute;height: 20px;width: 20px;}.seller { background-color: #0C0A02; position: absolute; height: 20px; width: 20px; font-size: 12px; border-color: red; border-width: 1px; border-style: solid; color: #E6EF0D; font-family: Verdana;}.gameover {background-color: transparent;border-width: 2px;border-style: solid;position: absolute;visibility: hidden;left: 200px;top: 200px;height: 50px;width: 500px;font-family: "Impact";font-size: 100px;}.character {background-color: #DD9999;/*#9999DD*/;border-color: #000000;border-width: 1px;border-style: solid;position: absolute;height: 19px;width: 19px;}body { background-color: white ;	visibility: visible;}.enter { 	visibility: visible;	font-family: Verdana;	font-size: 20px;	height: 100%;	width: 100%;	background-color: black;	border-color: #C81300;	border-width: 4px;	border-style: solid;}.inputa {	visibility: visible;	font-family: Verdana;	font-size: 20px;	height: 30px;	width: 300px;	background-color: #000000;	color: #F5E939;	border-color: #F5E939;	border-width: 4px;	border-style: solid;	position: absolute;	left: 350px;	top: 150px;	}.inputb {	visibility: visible;	font-family: Verdana;	font-size: 20px;	height: 30px;	width: 300px;	background-color: #000000;	color: #F5E939;	border-color: #F5E939;	border-width: 4px;	border-style: solid;	position: absolute;	left: 350px;	top: 200px;	}.inputc {	visibility: visible;	font-family: Verdana;	font-size: 17px;	height: 30px;	width: 300px;	background-color: #000000;	color: #F5E939;	border-color: #F5E939;	border-width: 4px;	border-style: solid;	position: absolute;	left: 350px;	top: 250px;	}#controller {background-color: #EFEFEF;border-color: #CCCCCC;border-width: 1px;border-style: solid;font-family: verdana;font-size: 10px;text-align: center;}</style><script language="JavaScript">var playername;var playerpass;function setPlayer() { document.getElementById("moi").style.visibility = "hidden"; document.getElementById("user").style.visibility = "hidden"; document.getElementById("pass").style.visibility = "hidden"; document.getElementById("buttona").style.visibility = "hidden"; playername = document.getElementById("user").value; playerpass = document.getElementById("pass").value; doInterval();}var checked = false;var objCount = 0;var xmlHttp;startTile = {x: 1, y: 8};var walktimer = 1;var map = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],[1, 2, 2, 2, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 4, 2, 2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 2, 2, 2, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 2, 2, 2, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 1, 1, 1, 2, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]; function shoot(obj, directshoot){ if (map[obj.y][obj.x] != 2) { if (directshoot == "right") {  for (xto = obj.x; xto < obj.x+10; xto++) {   if(map[obj.y][xto] == 3) {    name = "shot"+shotcount;     alert("u hit : "+playerMap[obj.y][xto]);    break;   } else if (map[obj.y][xto] == 1 || map[obj.y][xto] == 2) {	break;   }  } } else if (directshoot == "left") {  for (xto = obj.x; xto > obj.x-10; xto--) {   if(map[obj.y][xto] == 3) {    name = "shot"+shotcount;     alert("u hit : "+playerMap[obj.y][xto]);    break;   } else if (map[obj.y][xto] == 1 || map[obj.y][xto] == 2) {	break;   }  } } else if (directshoot == "up") {  for (yto = obj.y; yto > obj.y-10; yto--) {    if(map[yto][obj.x] == 3) {     name = "shot"+shotcount;      alert("u hit : "+playerMap[yto][obj.x]);     break;    } else if (map[yto][obj.x] == 1 || map[yto][obj.x] == 2) {	break;    }  } } else if (directshoot == "down") {  for (yto = obj.y; yto < obj.y+10; yto++) {   if(map[yto][obj.x] == 3) {    name = "shot"+shotcount;     alert("u hit : "+playerMap[yto][obj.x]);    break;   } else if (map[yto][obj.x] == 1 || map[yto][obj.x] == 2) {	break;   }  } } }}xOffset = 0;var xstore = [];var ystore = [];var playerstore = [];yOffset = 20;tileSize = 20;var shotcount = 0;var curDir = "up";var walktimer = 1;setInterval("walktimer--",100);var playerobject = [];// function myfocus()//{// var myinputa = document.getElementById("controller");//  myinputa.focus();// }// setInterval("myfocus()", 500);//function newObj(type, x, y) {name = Math.random()*1000000;char = "(!)";mystyle = "left: "+Number(x*tileSize+xOffset)+"px; top: "+Number(y*tileSize+yOffset)+"px";var newdiv = document.createElement('div');var divIdName = name;newdiv.setAttribute('id',name);newdiv.innerHTML = char;var useobj = document.body.appendChild(newdiv);useobj.style.position = "absolute";useobj.style.left = Number(x*tileSize+xOffset)+"px";useobj.style.top = Number(y*tileSize+yOffset)+"px";useobj.className = type;objCount++;return eval(useobj);} function drawPlayers() { for (i = 0; i < ystore.length; i++) {	if (playerstore[i] != playername) {	playerobject[i] = newObj("character",xstore[i],ystore[i]);	map[ystore[i]][xstore[i]] = 3;	playerMap[ystore[i]][xstore[i]] = playerstore[i];	} }} function removePlayers() { for (i = 0; i < ystore.length; i++) {	delete playerobject[i];	map[ystore[i]][xstore[i]] = 0;	playerMap[ystore[i]][xstore[i]] = 0; }} function stripPlayer(info) {removePlayers();xstore = [];ystore = [];playerstore = []; var players = info.getElementsByTagName("player"); for (i = 0; i < players.length; i++) {	xstore.push(players[i].childNodes[0].childNodes[0].nodeValue); } for (j = 0; j < players.length; j++) {	ystore.push(players[j].childNodes[1].childNodes[0].nodeValue); } for (k = 0; k < players.length; k++) {	playerstore.push(players[k].childNodes[2].childNodes[0].nodeValue); }drawPlayers();}function makeObj(type, x, y) {// <div class="type" style="top: xpx; left: ypx" />if (type=="wall") {name = type+"_"+x+"_"+y;char = "=";} else if(type=="safezone") { name = type+"_"; char = "";} else if(type=="seller") { name = type+"_seller"; char = "[$]";}else {name = type+"_"+objCountchar = "(!)";}writeThis = "<div id='"+name+"' class='"+type+"' style='left: "+Number(x*tileSize+xOffset)+"px; top: "+Number(y*tileSize+yOffset)+"px'>"+char+"</div>";objCount++;document.write(writeThis);eval(name).x = x;eval(name).y = y;eval(name).health = 100;return eval(name);}function assessMap() {for (y=0; y<map.length; y++) {for (x=0; x<map[0].length; x++) {if (map[y][x] == 1) {makeObj("wall", x, y);} if (map[y][x] == 2) {makeObj("safezone",x,y);}if (map[y][x] == 4) {makeObj("seller",x,y);}}}}assessMap();var mainChar = makeObj("character", startTile.x, startTile.y); //mainChar now acts as a reference to the div object for the character.function assessKeys(evt) {move = false;x = mainChar.x;y = mainChar.y;key = evt.keyCode;if (key == 97) {//LEFTmove = true;curDir = "left";x -= 1;} else if (key == 119) {//UPmove = true;curDir = "up";y -= 1;} else if (key == 100) {//RIGHTmove = true;curDir = "right";x += 1;} else if (key == 115) {//DOWNmove = true;curDir = "down";y += 1;} else if (key == 32) {shoot(mainChar, curDir);}if (move == true) {if ((map[y][x] == 0 || map[y][x] == 2) && map[y][x] != 3 && walktimer <= 0) {mainChar.style.left = x*tileSize + xOffset;mainChar.style.top = y*tileSize + yOffset;mainChar.x = x;mainChar.y = y;walktimer = 1;}}testDirections();}function getHit (obj) { health = obj.health; health -= 20; obj.health = health; if (obj.health <= 0) {	mainChar.x = 1;	mainChar.y = 28;	obj.style.top = y*tileSize+yOffset;	obj.style.left = x*tileSize+xOffset;	var gameover = document.getElementById("gameover");	gameover.style.visibility =  "visible";	setTimeout("gameover.style.visibility = 'hidden'", 2000);	obj.health = 100; } document.body.style.backgroundColor = "red"; setTimeout("document.body.style.backgroundColor = 'white'", 50);}function ajaxFunction(){	try 	 {  // Firefox, Opera 8.0+, Safari 	  xmlHttp=new XMLHttpRequest();  	} catch (e)   { 	 // Internet Explorer  	try    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }  catch (e)    {    try      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }    catch (e)      {      alert("Your browser does not support AJAX!");      return false;      }    }  }  xmlHttp.onreadystatechange=function()    {    if(xmlHttp.readyState==4)      {      player = xmlHttp.responseXML;      stripPlayer(player);      }    }  var combine = "savecoords.php?player="+playername+"&pass="+playerpass+"&x="+mainChar.x+"&y="+mainChar.y;  xmlHttp.open("GET",combine,true);  xmlHttp.send(null);  }function doInterval() { setInterval("ajaxFunction()",500);}function testDirections() {x = mainChar.x;y = mainChar.y;canUp = true;canDown = true;canLeft = true;canRight = true;if (map[y-1][x] == 1) {canUp = false;}if (map[y+1][x] == 1) {canDown = false;}if (map[y][x-1] == 1) {canLeft = false;}if (map[y][x+1] == 1) {canRight = false;}document.title = "Up: "+canUp+", Down: "+canDown+", Right: "+canRight+", Left: "+canLeft;}</script></head><body onKeypress="assessKeys(event)"><div id="gameover" class="gameover"><h1><font color="red">GAME OVER</font></h1></div><div id="tester"></div><p class='enter' id='moi'><input type='text' id='user' class='inputa' value='Enter Username'><br><input type='password' id='pass' class='inputb' value='Enter Password'></p><input type='button' class='inputc' value='login' onclick='setPlayer()' id='buttona'></body></html>

I think the contents of the Array are being deleted but not the div object itself.this are the functions:stripPlayers();newObj();drawPlayers()removePlayers();that are involved with the process.

Link to comment
Share on other sites

Your code is long, jsut tell me which line is the one you're using to remove the <div>I searched through your code and you haven't made use of the DOM removeChild() function. There's no way you can delete a <div> without that.

Link to comment
Share on other sites

This is the code involved:

function removePlayers() { for (i = 0; i < ystore.length; i++) {	delete playerobject[i];	map[ystore[i]][xstore[i]] = 0;	playerMap[ystore[i]][xstore[i]] = 0; }

With the removeChild() function do i pass as argument the ID of the div object

Link to comment
Share on other sites

You need to reference the object itself to use removeChild.Here's the best way to use removeChild:_obj.parentNode.removeChild(_obj);Where _obj is the <div> object you're trying to delete. You can reference it anyhow. Using getElementById, or getElementsByTagName.

Link to comment
Share on other sites

I have my objects stored in playerobjects[] could that be my reference to my object if so i get the error that i have an invalid argument.

Link to comment
Share on other sites

Well, if the DOM node itself is stored in the playerobjects array then you can do it.Like this: playerobjects[3].parentNode.removeChild(playerobjects[3]);The node could only be in the playerobjects array if you assigned the node to the variable sometime or another.For example this: playerobjects[3] = document.createElement("div")or this: playerobjects[3] = document.getElementsByTagName("div")[5];or this: playerobjects[3] = document.getElementById("box");

Link to comment
Share on other sites

well it goes more like this

function makemeadiv() { mydiv = document.createElement("div"); return mydiv;}playerobject[] = makemeadiv();

that's like the way it goes.

Link to comment
Share on other sites

That should work correctly. To delete a <div> just do it like this:playerobjects[X].parentNode.removeChild(playerobjects[X]);Where X is the element of the array you're trying to delete.

Link to comment
Share on other sites

I think this code goes well for a time , but i get an undefined in array i don't know how? Then i get this error: playerobject[...].parentNode is empty or isn't a object

Link to comment
Share on other sites

Try alert(playerobject[X]); (where X is one of the elements of the array) and tell me what it shows you. It should return "[object HTMLDivElement]".

Link to comment
Share on other sites

It goes like this:[object][object][object]undefined[object][object]EDIT: Im using IE, so the alert box it's outcome may be different

Link to comment
Share on other sites

Oh, Internet Explorer. Hmm, well, in Internet Explorer almost everything is an object. But at least I know it's not a number or string.Have you appended these <div> tags to the body or somewhere?If you haven't appended the node somewhere it won't have a parentNode.Try document.removeNode(playerobject[X]); and see if it works.

Link to comment
Share on other sites

I appended the Child to the body tag this way "document.body.appendChild(mychild);"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...