开发者

javascript unable to call method in __prototype__, says Object [object Object] has no method 'display'

RESOLVED, WAS AN ERROR IN MY CODE

I'm testing out the moo4q jQuery-MooTools synthesis (http://moo4q.com/) on a simple game and am running into an issue. Here's the snippet of code that's causing the problem:

// write score counter, puts up overlay, load image
initGame: function () {

    this.app.unbind('loadingDone',this.initGame);

    this.setupHUD();
    this.gameObjects['scoreCounter'].html('1000');
    var imgLib = this.imgs[this.gameType];
    var img = imgLib.getUniqueImage();
    this.log(img);
    img.display(this.gameObjects['imageHolder']);

    this.gameObjects['overlay'].fillRect(0, 0, 320, 460);
    $(this.gameObjects['overlay'].canvas).bind('click', $.proxy(this.pokeHole, this));

},

As explanation, this.gameObjects['imageHolder'] is a canvas context passed to the img object to tell it where to draw. Specifically on the line 'img.display(this.gameObject['image开发者_如何学编程Holder']); I am getting the error

Uncaught TypeError: Object [object Object] has no method 'display'

from Chrome

The output of the log trace called on the line just before the call (which is just a wrapped window.console.log) is:

[Class.newClass.constructor
 file: Object
 keyword_list: Array[1]
 options: F
 __proto__: Object
   canvasContext: null
   checkResponse: function (){
   constructor: function (){
   display: function (){
   file: null
   initialize: function (){
   keyword_list: Array[0]
   log: function (){
   options: Object
   __proto__: Object

I thought, maybe, that it would call the display as extended with the proto? But it seems not. this.imgs[this.gameType] is a class ImageContainer. getUniqueImage looks like this:

// gets a random image from the imgsShown array, then removes it
// so that subsequent calls to getUniqueImage will always
// be unique.  Refills imgsShown if empty.
getUniqueImage: function() {

  // copy over the img array if imgsShown array is empty
  if(this.imgsShown.length == 0) this.imgsShown = this.imgs.slice(0);
  var rand = Math.floor(Math.random() * this.imgsShown.length);

  return this.imgsShown.splice(rand,1);
}

Whole picture here (breaks when Animals is clicked):

http://www.clumsyfingers.net/projects/game/revealer/

the most relevant files are in an /apps directory I have left open

http://www.clumsyfingers.net/projects/game/revealer/app/

Halp?


var img = imgLib.getUniqueImage();

is imgLib an array/html collection? if so, img is an object?

img.display(this.gameObjects['imageHolder']);

Are you prototyping Object? That's not a good idea, if you were. I suggest you refactor by doing a class method displayImage and just call that instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜