Skip to main content
Participant
October 24, 2023
Answered

How do I change the value of a variable that was declared on the main timeline from a movieclip?

  • October 24, 2023
  • 1 reply
  • 327 views

I am using canvas/javascript.

 

I have a variable that I declared and gave a value of false on the main timeline.

var end = false;

I want to use this to track when a movie clip, named 'ani' that is on the main timeline, has reached its last frame.

 

I have tried multiple methods and none are working.

 

On the last frame of 'ani' I have tried...

this.parent.end = true;

 and

exportRoot.end = true;

 Neither worked.

If I do 'console.log' from within 'ani' it prints 'true'. But if I do 'console.log' from the main timeline it prints 'false'.

 

What am I doing wrong?

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

    Hi.

     

    Variables are only accessible in the frames in which they are declared. If you want to access a value somewhere else, you need to create a property instead of a variable. Like this:

    this.end = false;

     

    I hope this helps.

     

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    October 24, 2023

    Hi.

     

    Variables are only accessible in the frames in which they are declared. If you want to access a value somewhere else, you need to create a property instead of a variable. Like this:

    this.end = false;

     

    I hope this helps.

     

    Regards,

    JC

    Participant
    October 24, 2023

    Hi, same person, different account.

    I replaced 

    end = false;

    with

    this.end = false;

    but I am still having issues.

     

    How do I access this variable from within a movie clip or from within a function?

    JoãoCésar17023019
    Community Expert
    Community Expert
    October 24, 2023

    If you created the property in the main timeline, then exportRoot.end should work.