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

Help - global variable not working as global variable.

New Here ,
Jan 20, 2013 Jan 20, 2013

So I am just doing a basic form. Frame one has flash components like radio buttons, text input, yada yada ya, frame 02 just has a summary. Everything works perfectly, except for my variables which store the first name and last name that is enterered into the text input fields and I don't know why its not working. I have tried numerous different methods and nothing seems to work. I am guessing it has something to do with the variable scope, but there is nothing I have done to make it local. In fact, I have initiated those variables alongisde another, and within the same function I assign a value to one variable and it works, and when I assign values to the first and last name variables, it will not transfer over to 2nd frame, even though its written in the exact same manner as another that works. Here is frame 01:

var year:String = "";

radio_00.addEventListener(MouseEvent.CLICK, radio)

radio_01.addEventListener(MouseEvent.CLICK, radio)

radio_02.addEventListener(MouseEvent.CLICK, radio)

radio_03.addEventListener(MouseEvent.CLICK, radio)

function radio(e) {

    if (radio_00.selected) {

        year = "0";

    }

    if (radio_01.selected) {

        year = "1-2";

    }

    if (radio_02.selected) {

        year = "3-4";

    }

    if (radio_03.selected) {

        year = "5+";

    }

}

var living:String="";

var firstN:String="";

var lastN:String="";

done_btn.addEventListener(MouseEvent.MOUSE_UP, done)

function done(event:MouseEvent) {

    if (live_box.selected) {

        living = "do";

    } else {

        living = "do not";

    }

    var lastN = last_txt.text;

    var firstN = first_txt.text;

    trace(living);

    trace(firstN);

    trace(lastN);

    gotoAndPlay("end");

}

stop();

and now frame 02:

stop();

textArea_txt.text =

"My name is " +firstN+ " " +lastN+ ".\nI have " +year+ " years of post-seconday experience.\nI " +living+ " live in Saskatchewan.";

***THE VARIABLES firstN and lastN HAVE A BLANK VALUE HERE, NOT NULL, JUST BLANK. I HAVE NO IDEA WHY, FOR IF YOU LOOK AT HOW THE VARIABLE living IS DECLARED AND ASSIGNED A VALUE, ITS ALMOST THE SAME. ANY HELP WILL BE MUCH APPRECIATED

TOPICS
ActionScript
505
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

correct answers 1 Correct answer

LEGEND , Jan 20, 2013 Jan 20, 2013

You are decalring entirely new variables inside the function and their scope is limited to within the function.  You should only be assigning the values to the ones you declare outside.  The ones outside will have global scope so long as the layer that the code is in extends the full length of the timeline...  inside the function should only be...

    lastN = last_txt.text;

    firstN = first_txt.text;

Translate
LEGEND ,
Jan 20, 2013 Jan 20, 2013

You are decalring entirely new variables inside the function and their scope is limited to within the function.  You should only be assigning the values to the ones you declare outside.  The ones outside will have global scope so long as the layer that the code is in extends the full length of the timeline...  inside the function should only be...

    lastN = last_txt.text;

    firstN = first_txt.text;

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 ,
Jan 20, 2013 Jan 20, 2013
LATEST

Ned my man, you are a genius! Thank you!

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