A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: input text box not storing variables?

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    41

    input text box not storing variables?

    i want to get a user to input into an input box. they do this and the code im using is:

    var tempstring:String;
    tempstring = inputstring;

    all variable names on the input boxes are working

    however when i trace tempstring this is what it says in output

    <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="29" COLOR="#000000" LETTERSPACING="0" KERNING="0">3</FONT></P></TEXTFORMAT>

    of course i want it to read the one character they enter into the inputstring box. what am i not doing here?

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    You have to use Instance name and not Variable name. Put "inputstring" in the Instance name of your input texboxes, and not in the Variable Name.

    And add .text like this: tempstring = inputstring.text;
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    Member
    Join Date
    Aug 2008
    Posts
    41
    ah not at the pc with it on atm, i already tried the .text thing and that didnt work but im pretty sure the instance name doesnt store the value, its the variable which does this . . running trace like i said has my variable with data in it, just not the entered data, it seems to be storing the box's formatting properties :S

    thanks for reply, will get back to pc in next hr and give it another go with the instance name to be sure ,thanks!

    edit: putting the .text doesnt display all of the formatting code but running atrace now says that its undefined. using instance names give me the _level0.input
    Last edited by Demastras; 11-09-2012 at 06:58 PM.

  4. #4
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    You want the variable tempstring to trigger the input textbox data?

    If you get _level0.input , that means your inputstring textbox is empty. Try adding data to it manually on it, or instead you can do this:
    PHP Code:
    inputstring="this is my text, now the variable tempstring can trigger me!";
    var 
    tempstring:String;
    tempstring=inputstring.text;

    trace(tempstring); 
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    yours gives off undefined too Angel.

    PHP Code:
    inputstring "hello";
    var 
    tempstring:String;
    tempstring inputstring;

    trace(tempstring); 
    I also suspect you have the textfield rendered as html, turn it off or use
    PHP Code:
    inputstring.html true;
    inputstring "hello";
    var 
    tempstring:String;
    tempstring inputstring;

    trace(tempstring); 
    this is based on a textfield with instance name and var name of "inputstring", which in my opinion isn't a good idea to have the same names, maybe alter one of them just slightly.

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Fruitbeard (here we go again)...

    Mine don't give undefined, because I specified inputstring="this is my text, now the variable tempstring can trigger me!";

    I told Demastras to use Instance name instead of Variable name, then
    PHP Code:
    inputstring="this is my text, now the variable tempstring can trigger me!";
    var 
    tempstring:String;
    tempstring=inputstring.text;

    trace(tempstring); 
    You forgot to add the .text to my script Fruitbeard, that's why it gets undefined. I forgot to add it to, but in here
    PHP Code:
    inputstring="this is my text, now the variable tempstring can trigger me!"
    Now this is the fixed script:

    PHP Code:
    inputstring.text="this is my text, now the variable tempstring can trigger me!";
    var 
    tempstring:String;
    tempstring=inputstring.text;

    trace(tempstring); 
    Hope that helps Damastras
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  7. #7
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    A 747 was halfway across the Atlantic when the captain got on the loud speaker, "Attention, passengers. We have lost one of our engines, but we can certainly reach London with the three we have left. Unfortunately, we will arrive an hour late as a r esult." http://www.mmomesos.com/mesos/Maple-Story-NX-US.html

    Shortly thereafter, the passengers heard the captain's voice again, "Guess what, folks. We just lost our third engine, but please be assured we can fly with only one. We will now arrive in London three hours late."


    At this point, one passenger became furious. "For Pete's sake," he shouted, "If we lose another engine, we'll be up here all night!" http://www.mmohome.com

  8. #8
    Member
    Join Date
    Aug 2008
    Posts
    41
    Erm . . thanks for the replys guys but i dont want to initialise the string manually or hard code it. the user will enter their text string into an input box, i want this string to be stored as a variable to be saved in the program for later. when i do this and assign the string to a variable this is actually stored in the tempvariable i create

    <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="29" COLOR="#000000" LETTERSPACING="0" KERNING="0">3</FONT></P></TEXTFORMAT>

    So its actually storing the "3" i typed into the box BUT storing all this formatting junk as well. this is actually working but of couse when i say if(text = "3") for example its always going to be false as text is actually equal to <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="29" COLOR="#000000" LETTERSPACING="0" KERNING="0">3</FONT></P></TEXTFORMAT>

    Now there is a cheap work around and i say if(text ="<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="29" COLOR="#000000" LETTERSPACING="0" KERNING="0">3</FONT></P></TEXTFORMAT>") it works . . but that is crazy!


    EDIT: NM the above actually works but i didnt think id have to initialise the code elese where.

    thank you once again flash kit! I can carry on my development of a good idea i think i have for work. I will be posting more as its been a while since i programmed properly! .
    Last edited by Demastras; 11-21-2012 at 04:29 AM.

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Try something like this!!

    PHP Code:
    MyText.onChanged = function()
    {
        
    //MyInputString = MyText.text;
        //var TempString:String;
        //TempString = MyInputString;
        //trace(TempString);
        
    TempString MyText.text;
        if (
    TempString == "3")
        {
            
    TempString "Well Done!";
        }
        
    trace(TempString);
    }; 
    embedding the font as always.
    Last edited by fruitbeard; 11-21-2012 at 04:57 AM. Reason: Embedding font

  10. #10
    Member
    Join Date
    Aug 2008
    Posts
    41
    ive figured it out, thanks beard! im using the instance name thing and initialising the boxes in frame 1 of the file and then using a button to verify the data, working pretty good!

    Ill be opening up a new post about reading files from a notepad into flash next, ill just do at leasta days worth of searching the net before i start spamming questions.

    thanks again people . . just need a kick start back into this kind of work, as ive said above, its been a while!

  11. #11
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I can surely help with loading a textfile text into flash. Let me know.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center