Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

accessing/changing variable across frames

New Here ,
Sep 08, 2009 Sep 08, 2009

hey there

i just started using flash, following tutorials and such.  however some of them still use actionscript 2, and so i'm having trouble finding help on basic input text programming.

here's the idea:

its a simple adding "game" where 2 numbers are randomly generated and you have to input what you think the answer is (userAnswer).  then it adds the two numbers it just generated to produce correctAnswer, and checks it against userAnswer.  when you hit the check answer button, it moves the the score dialog frame and says whether its correct or not.

but im having 2 problems i think - 1 - i can't get the input textfield to assign the typed-in value to userAnswer (I'm trying userAnswer = inputAnswer.text; )  and - 2 - the second frame that has the score and "Correct!" / "Incorrect!"  dialog can't seem to access any variables from the first frame.

i've tried using two layers and keeping the variables on the second layer that spans both frames, but then the functions in the frames that you actually see can't change the variable to update it with the user's input.

i hope this makes sense and i can update the problem file if its needed.  i'm just using this as a way to learn flash so it doesnt have to be elaborate.

thanks!

TOPICS
ActionScript
935
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2009 Sep 08, 2009

variables defined in any frame exist everywhere thereafter as long as the object in which they were defined still exists.

so, you're problem is unlikely to be with the variables.  it's more likely that one or more textfields don't exist when you're trying to reference their text property.

to remedy, use:

var ans1:String = inputAnswer.text;

in the frame where the input textfield exists.  you can then use Number(ans1) to compare to the sum of your two numbers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 08, 2009 Sep 08, 2009

thanks so much!

i guess there's still a bunch of assumptions i'm making that i need to work out with the assumptions flash makes =P

i was able to do all the calculations on the first frame (now that i know i can assign them to variables to use on the second frame) so i can access all the textfields i need to, and i discovered that my biggest issue was within the function called when you hit the "check answer" button i was putting the gotoAndStop("secondFrame") before some calculations that needed the input box on the first frame.  d'oh.

anyway, thanks again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2009 Sep 08, 2009
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines