Copy link to clipboard
Copied
Hi,
i would like to call a simple function in Animate CC.
The function should start when the movie is loading.
A MovieClip on the timeline (cycle) should do something..
.YES. there ist the right INSTANCE name for cycle.
Code:
function Hallo() {
console.log("Hallo");//this works
this.cycle.x=300; //does not work
}
Hallo();
message Console:Uncaught TypeError: Cannot set property 'x' of undefined
you're losing context. try:
function Hallo(tl) {
console.log("Hallo");//this works
tl.cycle.x=300; //does not work
}
Hallo(this);
Copy link to clipboard
Copied
you're losing context. try:
function Hallo(tl) {
console.log("Hallo");//this works
tl.cycle.x=300; //does not work
}
Hallo(this);
Copy link to clipboard
Copied
Thank you.
And what should i write to call this function from/in another function?
function fl_MouseClickHandler()
{
console.log("clicked");
//how to call the Hallo(tl) function
}
Copy link to clipboard
Copied
with event listeners you can use the function.bind proxy:
this.whatever.addEventListener('click',fl_xxx.bind(this));
function fl_xxx(){
this.cycle.x+=30;
}
Copy link to clipboard
Copied
Yes, thank you. My question was related to the first question.
How can i call now the Hello function from the timeline also on click?
this.whatever.addEventListener('click',fl_xxx.bind(this));
function fl_xxx(){
//how to call from here the Hallo(tl) function?????????????
this.cycle.x+=30;
}
Copy link to clipboard
Copied
there are several ways to do that, but the most concise (afaik) is
var tl = this;
tl.whatever.addEventListener('click',f_xxx);
f_xxx()
function f_xxx(){
tl.whatever.x += 33;
}
Copy link to clipboard
Copied
OK, thanks- solved it and it's easier for me to use the scope keyword this.
this.moveCycle = function(){
this.cycle.x=300;
};
this.moveCycle(); //call function from Timeline from any frame
this.button_left.addEventListener("click", fl_MouseClickHandler.bind(this));
function fl_MouseClickHandler()
{
this.moveCycle();//call function on click
}
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now