Copy link to clipboard
Copied
Hi. I have all my javascript on one frame.
I want it to be accessible on any frame ie: so I don't have o copy and paste the same code a hundred times.
I know I have to use exportRoot but I'm not too sure where to put it.
ie: on every variable and every function.
This is some of my code for example.
this.stop();
createjs.Touch.enable(stage);
///////////////////////////////////////////////////////////////////
//Play music
var musicHandler = playMusic.bind(this);
this.btn_playMusic.addEventListener("click", musicHandler);
function playMusic() {
var bgMusic;
bgMusic = createjs.Sound.play("bgMusic"); //in library probably.
bgMusic.play();
this.btn_playMusic.removeEventListener("click", musicHandler);
}
///////////////////////////////////////////////////////////////////
// drag code
var roundItems = [this.ducky, this.doggy, this.froggy, this.helicopter, this.monkey, this.sunny, this.tania, this.flower];
for(var i = 0; i<roundItems.length; i++){
roundItems[i].on("mousedown", onMouseDown.bind(this));
roundItems[i].on("pressmove", onMouseMove.bind(this));
roundItems[i].on("pressup", onMouseUp.bind(this));
roundItems[i].originX = roundItems[i].x;
roundItems[i].originY = roundItems[i].y;
}
///////////////////////////////////////////////////////////////////
var nextHandler = nextFunction.bind(this);
this.btn.addEventListener("click", nextHandler);
function nextFunction() {
this.btn.removeEventListener("click", nextHandler);
this.gotoAndPlay("ducky");
}
Copy link to clipboard
Copied
OK - so I suppose I need to add that I want to access that code from another frame.
So a more exact question would be how do I do that?
Pseudo code
exportRoot."call function nextHandler"
Copy link to clipboard
Copied
So I tried this from another frame to try and access a function from frame 1
exportRoot.btn.addEventListener("click", nextHandler);
exportRoot.btn.removeEventListener("click", nextHandler); //to remove the listener afterwards