Skip to main content
chenjil43641795
Legend
August 31, 2018
Answered

ANCC HTML5,I can't get a variable after jumping

  • August 31, 2018
  • 1 reply
  • 661 views

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");
}

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    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

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    August 31, 2018

    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

    chenjil43641795
    Legend
    August 31, 2018

    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();

    JoãoCésar17023019
    Community Expert
    Community Expert
    August 31, 2018

    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