Jürg
The first is easier to understand: By using paper.setup / evaluate directly, you're bypassing the mechanism that creates a PaperScope object per script, thus you end up reusing the same scope for both scripts, and evaluate the 2nd script into it, over the first one. The first time this is executed, it is fine, since the sequence of calling setup / evaluate works. But once callbacks are called (e.g. resize), it is messed up, because the references to view / canvas have been overridden.
This can be solved by creating a new PaperScope and associating it with the global paper variable, before using it:
paper = new paper.PaperScope();
The other issue is that when using jQuery callbacks rather than Paper ones, the variable pointing to the active scope, which is the same as the global paper variable, does not get updated. There is no clean solution to this right now, but the easiest workaround is setting paper to the view's associated scope:
$(window).resize(function() {
paper = view._scope;
doLayout();
});
I think I will put this into a View#activate() method, which you can call on any such handler that requires the view and its associated scope to be addressed.
Jürg