A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: STUMPED! Variable type from TXT compare problem :(

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Posts
    7

    STUMPED! Variable type from TXT compare problem :(

    Hello Everyone

    I'm completely STUMPED on this one, it's been driving me crackers!

    This is what i'm doing :
    The AS3 script sends two variables to a PHP script which in turn saves them to a TXT file, works well.
    The AS3 script then reads the TXT file back and checks to see if they have been written.

    The TXT file has the following lines :
    var_1=Hello
    &var_2=12345678

    The AS3 script easily reads the varaibles back using the following lines :
    var variable_name;
    var variable_numb;
    variable_name = loader.data.var_1;
    variable_numb = loader.data.var_2;

    So variable_name now holds Hello, and variable_numb holds 12345678 and i check using the following :

    result.text = variable_name;
    result.numb = variable_numb;

    As you can see i did not need to do a toString();
    The variable contents were displayed, no matter if a number OR letter.

    So far so good and it works well BUT here's the problem :


    Now i want to compare the returned variables to see if they are the same as i sent.

    This works :

    if (variable_numb == 12345678)
    {
    result.text = "YES, the number is 12345678";
    }

    But the following will NOT work :

    if (variable_name == "Hello")
    {
    result.text = "YES, the name is Hello";
    }

    As a test i also tried this to see if the returned variable was a string, here's the line :


    result.text = variable_name + " Mate";

    What i see is this :

    Hello

    I should see this :

    Hello Mate

    I'm guessing it's a problem with the variable type returned from the txt film on var_1 & var_2.
    They don't seem to be string or integer but using == to compare the variables work fine with numbers but not strings.

    Can someone kindly point me in the right direction?
    Thanks

  2. #2
    Junior Member
    Join Date
    Aug 2017
    Posts
    7
    Just a bit more info, could it be due to the variables being a null string type?

  3. #3
    Member
    Join Date
    Oct 2016
    Posts
    54
    hello. just teading but not testing.
    it might be reading the line break.
    put var_1=Hello
    &var_2=12345678 on one line and test

  4. #4
    Member
    Join Date
    Oct 2016
    Posts
    54
    or just add a trailing & sign to each variable from the php file

  5. #5
    Junior Member
    Join Date
    Aug 2017
    Posts
    7
    Quote Originally Posted by Dezoid View Post
    hello. just teading but not testing.
    it might be reading the line break.
    put var_1=Hello
    &var_2=12345678 on one line and test
    My thoughts exactly!
    I already tried it and hey presto it worked, i came back on to update my post but thanks for your input.

    The TXT file now looks like this :
    var_1=Hello&var_2=1234567 (This i produced manually and uploaded) but generating it via PHP is a pain as the & is causing it to jump to the next line.

    Trying to solve the last part now with the &.
    Ron

  6. #6
    Junior Member
    Join Date
    Aug 2017
    Posts
    7
    Quote Originally Posted by Dezoid View Post
    or just add a trailing & sign to each variable from the php file
    Thanks again for your input Dezoid .

    I was adding the var_1= and the &var_2= in AS3 code but i'd like to do it from the PHP if possible.

    The PHP file currently writes in the following way :

    fwrite($fh, $name_data . $numb_data);

    The TXT file however has the variables on separate lines like this :

    var_1=Fred
    &var_2=1972

    What i need is this : var_1=Fred&var_2=1972 on the same 1st line.

    Could you help in adjusting the following so both variables are on the same line of the TXT file :
    fwrite($fh, $name_data . $numb_data);

    When i checked the TXT file with a HEX Editor the code 1D is present meaning the carriage return.

    Thanks
    Ron

  7. #7
    Junior Member
    Join Date
    Aug 2017
    Posts
    7
    NOW RESOLVED!

    Amazing how the simplest of things can be overlooked!

    The two text filds on the stage were set to MULTLINE, not SINGLE LINE, this caused a Line Break / Carriage Return to be added automatically to the string variable even though there was only 1 line of text typed within the input field. Hopefully this will help someone else fooled by this simple error.

    Happy days .
    Ron_UK

  8. #8
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    I made this function a while back to return strings without spaces if you need:

    that same problem happened to me.. I spent hours trying to figure out why a server token would not match and it was because the server would add a nullbyte carriage in java, and theres alot of parsestring functions and trim functions I ended up using to fix the problem. This one is just for spaces though but you can probably change it to fix new lines and stuff

    PHP Code:
    function trim(input){
    var 
    str "";
    for(
    i=0;i<input.split(" ").length;i++){
    str += input.split(" ")[i];
    if(
    == input.split(" ").length-1){
    return(
    str);
    }
    }
    }
    trace(trim("hey whats up")); 


    this one will get rid of new lines:

    PHP Code:
    function trim(input){
    var 
    str "";
    for(var 
    i=0;i<input.split("\n").length;i++){
    str += input.split("\n")[i];
    if(
    == input.split("\n").length-1){
    return(
    str);
    }
    }
    }
    trace(trim("hey whats up" "\n" "loll")); 


    hopefully fruitbeard throws in some one line fix that looks something like this:

    PHP Code:
    stringParseIntFunctionDuplexTimeSpaceContinum(traceBlaster5000("string rgeo " "\n" "fdsvxc")) 
    Last edited by AS3.0; 08-17-2017 at 09:29 PM.

  9. #9
    Member
    Join Date
    Oct 2016
    Posts
    54
    ok. you have.

  10. #10
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    sorry, wrong forum
    Last edited by fruitbeard; 08-21-2017 at 07:15 AM.

  11. #11
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    fruit I tried loading up your sites swf from a mobile swf loader but it wont show does your sites swf have like some password to get it running

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

    My site is not one bit adapted to mobile phones, however, it has nothing that would prevent it from loading up on anything *normal*.
    The site if fullly functional infront of me now on a pc browser. I'm happy.

    Start another thread Alloy, this chap is probably annoyed that they get emails because of you and I using their thread.

  13. #13
    Junior Member
    Join Date
    Aug 2018
    Posts
    4
    hopefully fruitbeard throws in some one line fix that looks something like this:

    PHP Code:
    stringParseIntFunctionDuplexTimeSpaceContinum(traceBlaster5000("string rgeo " "\n" "fdsvxc")) 

    Hahahahaha you made my day.

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