javascript mgraphic coding troubles (sorry now inside the javascript section)


    Mar 01 2012 | 4:13 pm
    I encounter lots of problems while trying to write some json prototype styled functions, and specially with referencing mgraphics across prototyped functions.
    Maybe it's a problem of javascript syntax and comes from me, but look at the code :
    mgraphics.init(); var max = mgraphics; max.relative_coords = 0; max.autofill = 0;
    width = this.box.rect[2] - this.box.rect[0]; height = this.box.rect[3] - this.box.rect[1];
    function grid(columns,lines, context) {
    this.context = context;
    this.columns = columns; if (columns === undefined || columns > 32 || columns < 1) { this.columns = 4; }
    this.lines = lines; if (lines === undefined || lines > 32 || lines < 1) { this.lines = 4; }
    this.draw(); this.process_amount(); this.step_size; }
    grid.prototype = {
    draw: function() { var background_color = [0.1, 0.1, 0.1, 1.0]; var color = [0.7, 0.7, 0.7, 1.0]; var thickness = 1;
    this.context.set_source_rgba(background_color); this.context.rectangle(0,0,width,height); this.context.fill(); this.context.set_source_rgba(color); this.context.set_line_width(thickness); this.context.set_line_cap("round"); this.context.set_line_join("round");
    for(i=0;i this.context.move_to((i + 0.5)*this.step_size, 0); this.context.line_to((i + 0.5)*this.step_size, height); }
    for(i=0;i this.context.move_to(0, (i + 0.5)*this.step_size); this.context.line_to(width, (i + 0.5)*this.step_size); } this.context.fill(); },
    process_amount: function() {
    if (this.columns > this.lines){ this.step_size = width/this.columns; } else this.step_size = height/this.columns; }
    };
    function bang() { mgraphics.redraw(); }
    var matrix = new grid (jsarguments[1],jsarguments[2], max);
    matrix.process_amount(); matrix.draw(); bang();
    max window tell me that max javascript parser doesn't recognise calls to mgraphics (written inside the draw function) as functions ....
    This must be a referencing error of my own, but is it possible to put mgraphics context into a var and pass it as arguments to functions ?

    • Mar 02 2012 | 12:04 am
      sorry, i forgot to put all the drawing commands into the paint function, but i still have the same problem referencing problem
      autowatch = 1;
      mgraphics.init(); mgraphics.relative_coords = 0; mgraphics.autofill = 0;
      var max = mgraphics;
      width = this.box.rect[2] - this.box.rect[0]; height = this.box.rect[3] - this.box.rect[1];
      function grid(columns,lines) {
      this.columns = columns; if (columns === undefined || columns > 32 || columns < 1) { this.columns = 4; }
      this.lines = lines; if (lines === undefined || lines > 32 || lines < 1) { this.lines = 4; }
      this.draw(); this.process_amount(); this.step_size; }
      grid.prototype = {
      draw: function() {
      var background_color = [0.1, 0.1, 0.1, 1.0]; var color = [0.7, 0.7, 0.7, 1.0]; var thickness = 1;
      mgraphics.set_source_rgba(background_color); mgraphics.rectangle(0,0,width,height); mgraphics.fill();
      mgraphics.set_source_rgba(color); mgraphics.set_line_width(thickness); mgraphics.set_line_cap("round"); mgraphics.set_line_join("round");
      for(i=0;i mgraphics.move_to((i + 0.5)*this.step_size, 0); mgraphics.line_to((i + 0.5)*this.step_size, height);
      for(j=0;j
      } }
      for(i=0;i mgraphics.move_to(0, (i + 0.5)*this.step_size); mgraphics.line_to(width, (i + 0.5)*this.step_size); }
      mgraphics.fill(); },
      process_amount: function() {
      if (this.columns > this.lines){ this.step_size = width/this.columns; } else this.step_size = height/this.columns; }
      };
      var matrix = new grid (jsarguments[1],jsarguments[2]);
      function paint() { matrix.process_amount(); matrix.draw(); }