Skip to main content
June 5, 2015
Answered

Transferring Variables

  • June 5, 2015
  • 2 replies
  • 405 views

So, in my game there are multiple frames for different "windows". Am keeping track of the score in a movieclip in a frame. Currently, if the user leaves that frame and comes back, the score is reset. Any way to make sure the score stays the same as it was?

This topic has been closed for replies.
Correct answer

Playing around I accidentally came across the answer, by declaring the variable public static var it worked, so thanks for your answers! Much appreciated.

2 replies

Correct answer
June 8, 2015

Playing around I accidentally came across the answer, by declaring the variable public static var it worked, so thanks for your answers! Much appreciated.

Ned Murphy
Legend
June 5, 2015

One way would be to keep the score movieclip in all frames and only have it visible when you want it to be.  Another way would be to keep a variable holding the score value that is in a layer that extends over all frames so that it is never left behind and can be used to re-assign the value to the movieclip when it is needed.

June 6, 2015

So I prefer your second option. To do so I would put the code holding the score value in the actions frame of that layer correct? I have tried to do that and it says "Access of undefined property". How do I make it so the variable is accessible outside the movieclip and even outside it's frame?

Ned Murphy
Legend
June 6, 2015

You extend that layer the length of the timeline.  Select the last frame on the (used) timeline of that layer, right click it and choose Insert Frame.  That extends accessibility of whatever variables/functions are in the starting frame to the whole timeline.