Sign in to follow this  

[web] Javascript: input and scoping issue

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)
    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

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

Sign in to follow this