Copy link to clipboard
Copied
Have a html5 canvas document.
I have an object called "brick2" in the root of an animate CC scene (with the same instance name).
Code looks like this:
function moveBrick() {
this.brick2=0;
}
var timer1 = setInterval(moveBrick, 100);
this.stop();
When I run the file in a browser the brick doesn't go to "0" x position. However if I write this script (putting the x position property outside the function) it all works fine:
function moveBrick() {
}
var timer1 = setInterval(moveBrick, 100);
this.brick.x=0;
this.stop();
Any ideas on what I am doing wrong? Have a real worry that is something completely obvious.
1 Correct answer
The 'this' inside the function isn't referring to the timeline. Here's one way around that:
var self = this;
function moveBrick() {
self.brick2=0;
}
var timer1 = setInterval(moveBrick, 100);
this.stop();
Copy link to clipboard
Copied
Moved from the Forum Lounge to the Adobe Animate CC - General forum.
Copy link to clipboard
Copied
The 'this' inside the function isn't referring to the timeline. Here's one way around that:
var self = this;
function moveBrick() {
self.brick2=0;
}
var timer1 = setInterval(moveBrick, 100);
this.stop();
Copy link to clipboard
Copied
Doesn't CreateJS specifically make a variable to track the root timeline too? exportRoot or something like that?
e.g. exportRoot.brick2.x should work globally too, if I'm recalling things right…
Copy link to clipboard
Copied
Great! that works - Thanks so much.

