From the description, you simply need to call a function which is within scope of your original sketch. That really has nothing to do with having multiple sketches interact with each other, which is more a question for the p5.js community anyway.
Try something like the following:
setup.p5promise = importScripts([
"https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.dom.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.sound.min.js"
]);
setup.mySketch = function (sketch) {
sketch.setup = function() {
sketch.createCanvas(200, 200);
};
sketch.draw = function() {
sketch.background(100 + sketch.sin(sketch.millis() * 0.005) * 60);
if (sketch.mouseIsPressed) {
setup.p5PlayPassage(sketch, "entrance");
}
};
};
setup.p5PlayPassage = function(sketch, passageName) {
sketch.remove();
Engine.play(passageName);
};
And:
<div id="p5sketch"></div>
<<script>>
$(document).one(':passageend', function () {
setup.p5promise.then(function () {
new p5(setup.mySketch, 'p5sketch');
});
});
<</script>>
That example is a bit contrived, however, since you do not need the extra function simply to remove the sketch and play a new passage. For example:
setup.mySketch = function (sketch) {
sketch.setup = function() {
sketch.createCanvas(200, 200);
};
sketch.draw = function() {
sketch.background(100 + sketch.sin(sketch.millis() * 0.005) * 60);
if (sketch.mouseIsPressed) {
sketch.remove();
Engine.play("entrance");
}
};
};