Copy link to clipboard
Copied
I can't get a variable after jumping.
This is the Start menu.
After jumping to a section, play to the end will jump back.
But you can't get a variable after jumping back(ezjxz1).
var ezjxz1;
var ezjxz2;
var ezjxz3;
var ezjxz4;
console.log(ezjxz1)
if(ezjxz1==1){this.sbxz1.gotoAndStop(2);}
if(ezjxz1==1&ezjxz2==1&ezjxz3==1&ezjxz4==1)
{
this.gotoAndPlay("daoqian");
}
this.stop();
this.sbxz1.addEventListener("click", sbxz1cx.bind(this));
this.sbxz2.addEventListener("click", sbxz2cx.bind(this));
this.sbxz3.addEventListener("click", sbxz3cx.bind(this));
this.sbxz4.addEventListener("click", sbxz4cx.bind(this));
function sbxz1cx()
{
ezjxz1=1;
this.gotoAndPlay("bingxiang");
}
function sbxz2cx()
{ ezjxz2=1;
this.sbxz2.gotoAndStop(2);
this.gotoAndPlay("gongxiang");
}
function sbxz3cx()
{ ezjxz3=1;
this.sbxz3.gotoAndStop(2);
this.gotoAndPlay("saodi");
}
function sbxz4cx()
{ ezjxz4==1;
this.sbxz4.gotoAndStop(2);
this.gotoAndPlay("mensuo");
}
Hi.
Instead of:
var ezjxz1;
var ezjxz2;
.
.
.
Write:
this.ezjxz1;
this.ezjxz2;
.
.
.
Because 'var ezjxz1' will make the variable only available to that frame where it is declared. When you use 'this' you are adding/changing a property/method of/to the current object you're in.
To sum up:
ezjxz1 = 1; (you're declaring a global value)
var ezjxz1 = 1; (you're declaring a value for that frame only)
this.ezjxz1 = 1;(you're adding/changing a property for that entire timeline. For that object)
I hope this helps.
Regards,
...Copy link to clipboard
Copied
Hi.
Instead of:
var ezjxz1;
var ezjxz2;
.
.
.
Write:
this.ezjxz1;
this.ezjxz2;
.
.
.
Because 'var ezjxz1' will make the variable only available to that frame where it is declared. When you use 'this' you are adding/changing a property/method of/to the current object you're in.
To sum up:
ezjxz1 = 1; (you're declaring a global value)
var ezjxz1 = 1; (you're declaring a value for that frame only)
this.ezjxz1 = 1;(you're adding/changing a property for that entire timeline. For that object)
I hope this helps.
Regards,
JC
Copy link to clipboard
Copied
This prompt appears after the "if" decision
Object doesn't support property or method 'gotoAndPlay'
function ezjpdcx()
{
if(this.ezjxz1==1&this.ezjxz2==1&this.ezjxz3==1&this.ezjxz4==1)
{
this.gotoAndPlay("daoqian");
}
}
ezjpdcx();
Copy link to clipboard
Copied
It's a matter of scope.
In your case, "this" is referring to the Window object. Try console.log(this) inside of your function body and you'll see.
The safest way in my opinion to solve this scope issue is to use the automatically declared "exportRoot" property if you're referring to the main timeline or to use a variable to store the scope like this:
var that = this;
function ezjpdcx()
{
if (that.ezjxz1 == 1 & that.ezjxz2 == 1 & that.ezjxz3 == 1 & that.ezjxz4 == 1)
{
that.gotoAndPlay("daoqian");
}
}
Regards,
JC
Copy link to clipboard
Copied
Thank you for your answer.
The problem is solved, but there is a new problem.
"gotoAndPlay"Cannot play,
Write in other places, gotoAndPlay can be played,
but the code is written to stop after the jump, will not play
Is it a code problem or is it because I'm animating too much?
Now, I need to delete a lot of animations to test the code.
Copy link to clipboard
Copied
JoãoCésar wrote
var ezjxz1;
var ezjxz2;
.
Write:
this.ezjxz1;
this.ezjxz2;
No, don't write that. All that does is attempt to access a nonexistent property and returns undefined. There's no need to declare object properties. Just assign to them when you're ready to assign to them. But if you really, really want to "declare" a property before it's used, you could do something like this.ezjkx1 = 0; etc...
JoãoCésar wrote
It's a matter of scope.
Context, technically. Context is the current value of "this". Scope is the current scope chain for resolving variables. Since JavaScript uses lexical scope, a function can be executing in global context but local scope at the same time. For example, your code above that accesses the local variable "that".