0

I am getting a TypeError on the variable "pattern" and my script does not execute past the marked break point. I am using the JCanvas and JQuery and all dependencies are in place. What is the reason for the error. There is a similar implementation used here.

function drawMe(thumbUrl){
  function drawThumb(){
    $("canvas").drawRect({
      //Code breaks here.
      fillStyle: pattern,
      x: 200, y: 100,
      width: 250, height: 100,
      fromCenter: false         
    });
  }

  var pattern = $("canvas").createPattern({
    source: thumbUrl,
    repeat: "repeat",
    load: drawThumb
  })

}

drawMe("http://placehold.it/100x100");
smulholland2
  • 1,143
  • 2
  • 14
  • 28

2 Answers2

2

i think you need to change this

function drawThumb(){
    $("canvas").drawRect({
      //Code breaks here.
      fillStyle: pattern,
      x: 200, y: 100,
      width: 250, height: 100,
      fromCenter: false         
    });
  }

to this

function drawThumb(pattern){
    $("canvas").drawRect({
      //Code breaks here.
      fillStyle: pattern,
      x: 200, y: 100,
      width: 250, height: 100,
      fromCenter: false         
    });
  }
rahul
  • 7,573
  • 7
  • 39
  • 53
  • I don´t think so. 'pattern' is a var defined later on. But there´s something completely mixed up. The var-definition references to 'thumbUrl' which is not defined previously but is defined as a function parameter before. I would say: restructure your code, use a debugger. – cljk Oct 15 '12 at 07:10
0

I had this problem on Chrome. After restarting chrome it solved me the problem...

jbaylina
  • 4,408
  • 1
  • 30
  • 39