Paper.js: ImportSVG returns undefined

Created on 22 Jun 2015  路  3Comments  路  Source: paperjs/paper.js

When importing the ghostscript tiger in javascript, no value is returned from project.importSVG. The graphic is displayed correctly.

Expected behavior:
importSVG returns a reference to the Item containing the SVG.

Current behavior:
importSVG returns undefined.

paper.setup(document.getElementById("paper_canvas"));
var svg = paper.project.importSVG("img/ghostscript_tiger.svg");
console.log(svg); // => undefined

Most helpful comment

You need to use an onload callback function to know when the file is loaded:

paper.project.importSVG("img/ghostscript_tiger.svg", function(item) {
    console.log(item);
});

All 3 comments

You need to use an onload callback function to know when the file is loaded:

paper.project.importSVG("img/ghostscript_tiger.svg", function(item) {
    console.log(item);
});

Thanks!

The documentation doesn't mention callback functions (and I was a bit surprised that the docs suggested it would be a blocking call in js). Is there somewhere I can contribute to the documentation?

Yeah that feature was added later. Hard to keep it all in sync...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eugene-rozov picture eugene-rozov  路  6Comments

eljefedelrodeodeljefe picture eljefedelrodeodeljefe  路  5Comments

techninja picture techninja  路  4Comments

9oelM picture 9oelM  路  5Comments

hapticdata picture hapticdata  路  5Comments