I am trying to save fabricjs stickman example by using JSON.stringify and load it back using canvas.loadFromJSON, I even add the properties of circle line1, line2, line3 and line4 explicitly to the JSON using the following way
var jsonSave = JSON.stringify(canvas.toJSON(['line1', 'line2', 'line3', 'line4']));
Although i can see that the saved JSON contains the above mentioned properties, but when I load from JSON and try to move the circle I get an error as Uncaught TypeError: p.line1.set is not a function.
I don't understand why before saving set was a function but after saving and load from JSON its not?
Also is there any other way to make the stickman work without using set method so that it doesn't break after we save it and load it from JSON.
I did look up for similar problems and this link was the most similar problem i could find but the solution provided in this answer, also didn't seem to solve the problem of save and load.
loading stickman from json does not persist line coordinate rotation logic
I have also attached the fiddle link below. To reproduce the scenario
- Try to move any circle after fiddle loads.
- Click on the save button. (you can go to developers tool and see under the resources tab for the JSON stored in the sessions storage.)
- Click on load button.
- Try to move any circle and look at console tab in developers tool.
http://jsfiddle.net/hkundnani/h0sf3x5h/5/
Any help would be greatly appreciated.. Thanks..