Stiggy88 Posted August 18, 2014 Share Posted August 18, 2014 Hi Guys, I have a question of obtaining some form of a unique ID from a sprite / button, let me explain. I have a main menu which loads a random number of items which are clickable (at the moment they are buttons, which I'm not sure is correct or if they should be sprites). I also have a JS object which represents each of these created items (the objects are put into an array). At the moment when the Phaser button is created (in a for loop), I attach the button to the JS object when it is created, so that it is stored. As a callback function on the clickable button, I try and pass the unique ID of the object so that I can quickly access which ever object is attached to that particular button and get all the details. However, when I alert the unique ID on button click, it keeps displaying the same one, regardless of the button I click. Now I know this must be wrong and I presume I should be attaching the custom object to the button instead, but I'm not too sure how to do that. If that is also incorrect, what steps should I take to link my object to a clickable button/sprite? The idea is that once a button is clicked, a small menu dialog appears with the details etc. depending on the item clicked Many Thanks! Link to comment Share on other sites More sharing options...
lewster32 Posted August 18, 2014 Share Posted August 18, 2014 Hard to say without seeing code what the problem is here, but I've got a jsFiddle which shows how to retrieve information added to a button instance upon clicking: http://jsfiddle.net/lewster32/2U97k/ phaserdragoon 1 Link to comment Share on other sites More sharing options...
Stiggy88 Posted August 18, 2014 Author Share Posted August 18, 2014 Perfect! Sorry for the unclear question, especially for the simple answer. I very much appreciate the example too! Link to comment Share on other sites More sharing options...
Recommended Posts