1

I'm currently working on business card designing platform using fabrics.js.

I'm trying to implement auto-save feature which protects users from losing work by saving and restoring the designing data in browser cache.

So I used loadFromJSON() of Fabrics.js Canvas object to restore the designing data.

But I'm getting following error when I try to restore shape item from the JSON.

Uncaught TypeError: Cannot read property 'async' of undefined

Following is the my fiddle to test this. I have embedded raw JSON in the javascript.

https://jsfiddle.net/asgriksen/mhf2kqzo/14/

Thanks.

  • The link is missing. Can you edit your post and add it? – R.Rusev Oct 21 '16 at 20:06
  • Sorry, I just added the fiddle link. – Asgeir Ulriksen Oct 21 '16 at 20:14
  • I tried toDatalessJSON() and loadFromDatalessJSON() instead of toJSON() and loadFromJSON(), but I got the same error. – Asgeir Ulriksen Oct 21 '16 at 20:15
  • Check out http://stackoverflow.com/questions/24384804/fabric-js-subclassing-fabric-group-error-cannot-read-property-async-of-und. If you are using a custom class (which it sounds like 'shape' is), there's a couple of gotchas. – Ben Oct 21 '16 at 21:38

1 Answers1

0

The object at index 4 is a object of type shape. There is no fabric object of that type. I will assume you created a custom class for that object?

If so you need to add it to fabric so it can find it when trying to rebuild that object from the json. Assuming you have a new fabric shape class in a variable called Shape of which the data you link to is already set to type of shape you just need to add it to fabric like this

fabric.Shape= Shape;
fabric.Shape.async = false;

now fabric should be able to find the class when you load in the data.

if you still have issues with this I recommend including more of the code in the jsfiddle.

StefanHayden
  • 3,569
  • 1
  • 31
  • 38