this is my simplified code
my button class:
Button(x, y, image){
init: function(){
......
this.image = image;
.....
}
onClick: function(){
var name = game.data.itemdatabase[this.image][0];
var price = game.data.itemdatabase[this.image][1];
game.data.item.push{
[name, price];
};
};
draw: function(context){
//drawimage and stuff
context.drawImage(this.image,0 ,0);
}
}
in something.objectcontainer, i call the button in the init method:
var imageName = "itemA";
var a = new Button(x, y, imageName);
this.addChild(a);
The problem happens in the Button class.
if i check the this.image value in init(), it returned string, all is okay, even to the end of the init() method.
however, once i check this.image in the beginning of onClick() or draw() method, it returned with [object HTMLImageElement].
there's nothing in my code that involved adding dynamic DOM element or even related to DOM element. it was get and set data to the game.data variable.
and other functions who reference to this game.data.item
and strangely if i do some .src splitting in the Button onClick method to get the filename, and save the result to the game.data.item, somehow other functions who get the data from game.data.item still got the [object HTMLImageElement] as the value (i check that it was string before i set it to game.data.item). The problem disappeared when I add the resources manually to game.resources to it would be loaded along in melonjs preload. (both name and imageName has the name: ie. { name: "itemA", type:"image", src:"data/img/items/itemA.png"}.
the HTMLImage element doesn't give any problem for drawImage method, but I was going to use the string to call up data in the json because my JSON key is the string.....