Skip to main content
gamedev.net
🔒 Locked

[web] Javascript: input and scoping issue

Started by R1techie 0 replies 650+ views
Original Post
R1techie
R1techie
Dear Gamedev, javascript is by far one of the weirdest languages I've worked with. It's puppy dogs and lollipops on the outside and really easy to use when you want to do some simple things but the second start applying some intense structure to it the gremlins come out. My problem right now I'm making a map that has the ability to pan, and zoom. the problem is right now I'm adding a compass picture on top of the map and when it;s fully image mapped it should be able to be your buttons for panning. My problem is the map has been constructed in the Prototype classing so I can run multiple instances of it. because it's an instance and I'm placing direct HTML into a Div I need to be able to retrieve the name of the instance as a string so I can send it back to the div. Is there a way to retrieve the name of the current instance from within the instance in javascript without just directly passing a parameter that is a string on the name? <pre> MapWrapper.prototype.addOverlay= function(imgDiv) { that=this; GetMapDiv(imgDiv).innerHTML = "< I M G id= '" + that.mapID + "Compass' src='ZoomyThing.png' width='50' height='50' " + "usemap='#" + that.mapID + "CompassMap' />" + "<map id ='"+ that.mapID + "CompassMap' name='"+ that.mapID + "CompassMap'>" + "<area shape ='rect' coords ='7,0,13,13'" + " onclick='" + that+ ".Pan('W');' />"; } </pre>
Kylotan
Kylotan
Prototype-based languages can be tricky, yeah. But generally it's just a different syntax on the same old concepts. Could you be explicit about what 'instances' you're referring to, what you mean by their 'name', and why you need javascript names in your HTML? Generally you should be able to use 'this' and that will refer to the instance in question, so if that doesn't work, I think something else is going wrong, either in your code, or in how you expect it to work.<br><br>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.