Wednesday, 15 June 2011

javascript - KineticJS Node.create from JSON object literal -


I am trying to load a layer (trying with a layer and trying with the phase Am) which I have saved as a JSON object with Kinetic JS .toJSON () method. I'm debugging my script and it seems to be all right until the ninetric Node Here's my code:

  var forum = new kinetic Step ({Container: 'Container', Width: 1000, Height: 650}); Var check; $ (Document) .on ({click: function () {check = stage.toJSON ();}}, '# save'); $ (Document) .on ({click: function () {try {// parse check string object varal = JSON.parse (check); // check if s object is literal if (Object.prototype.toString calls ( S) === '[object object]') {// This is where the code prevents the execution of the code = connetic.Node.credit (s, container); stage.draw ();}} cache ( E) {Console.debug (e.stack); console.trace ();}}}, '# load');   

My HTML:

  & lt; Div id = "container" & gt; & Lt; / Div & gt; & Lt; Div id = "button" & gt; & Lt; Button id = "save" & gt; Save & lt; / Button & gt; & Lt; Button ID = "Load" & gt; Load & lt; / Button & gt; & Lt; / Div & gt;   

and error log:

  SyntaxError: unexpected token on object. On the function. (Native) .Netic HTMLButtonElement at Node.create (http: /d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.4.min.js:2:25166) $ On.click (http: //localhost/mosaicos/main.js: 181: 38) at HTMLDocument.b.event.dispatch (http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery .min.js: 3: 28337) at HTMLDocument.v.handle (http: //ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3/305042)   

Not sure if I am doing something wrong, any help would be greatly appreciated.

Kinetic.Node.create The same string you saved ( Check ) is required to pass and if the passes are not JSON string ( s ), then your order must be seen as such:

  Var newNode = Kinetic.Node.create (stage.toJSON ());   

Replace the stage toJSON with the variable where you saved that string.

This should give you the right idea. Alternatively, open the developer tool and put a breakpoint after saving. Copy the value of variable which is now included as a JSON string and then done as a copy in Kinetic.Node.create in console With string

No comments:

Post a Comment