Sign in to follow this  

[web] Javascript: input and scoping issue

This topic is 3639 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

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');' />";
                           

}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this