A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Quick thing about Text files

  1. #1
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167

    Quick thing about Text files

    Hey,

    This is probably an easy question. Ok say you have a text file that contains simply this:

    comment1=0

    Now in Flash, at the click of a button, you want to store inside a variable, the number contained inside the text file but added by one. So in this case, it would store instead of a zero, a one.

    So when you click the button, it would be something like:

    code:

    on (release) {
    myText = new LoadVars();
    myText.onLoad = function() {
    numberComment = this.comment1;
    inputComment = numberComment+1;
    };
    myText.load("text files/commentVariable.txt");
    }



    But when I run it, it just simply puts a zero (the number stored inside the text file) with a one beside it.

    Any thoughts ?

  2. #2
    Senior Member
    Join Date
    May 2005
    Location
    Brooklyn, NY
    Posts
    129
    Hi Osteel. I'm not sure if I am having a hard time understanding what you're saying or if you really do have it reversed. But here is what I would do.I normally make Movie clips into buttons but I will do it both ways since I see a button handler.

    With a Movie clip doubling as a button
    //GIVE THE BUTTON AN INSTANCE NAME OF myText
    //GIVE THE DYNAMIC TEXT FIELD THE VARIABLE comment1
    var comment1:Number = 0;
    _root.myText.onPress = function(){
    _root.comment1++;
    }
    With a Button Instance
    //GIVE THE DYNAMIC TEXT FIELD THE VARIABLE comment1

    //ON THE MAIN TIMELINE
    var comment1:Number = 0;
    //ON THE BUTTON ITSELF
    on (Release){
    _root.comment1++;
    }
    With that you should be set. I am not really familiar with your coding though. have you been in actionscript since the beggining??
    Best of luck
    -Sergio

  3. #3
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Hey Soig,

    I know how to increment values in Flash, Ive been using Flash for about two years just learning things as I go.

    No, the problem Im facing is grabbing a variable from the text file, and then incrementing that value by one inside a variable contained in flash. I thought I knew how, but it seems its not working

    Oh well, its more of a curiousity then a problem I suppose.

  4. #4
    Junior Member
    Join Date
    Apr 2006
    Posts
    7

    Convert to number

    Hi Osteel... Ive this same problem and the solution for this is converting the string variable to number with Number(); object...

    something like..

    System.useCodepage = true;
    loadVarsText = new LoadVars();
    loadVarsText.load("data.txt");
    loadVarsText.onLoad = function(success) {
    if (success) {
    p1 = new Number(this.variable1);
    }
    p++
    };

    but dont work!!! .... tell me if you can make it.

  5. #5
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    rgallegos@aurea,

    you are correct and close. This will work

    PHP Code:
    on (release) {
        
    myText = new LoadVars ();
        
    myText.onLoad = function () {
            
    numberComment Number(this.comment1);
            
    inputComment numberComment+1;
            
    trace(inputComment);
        };
        
    myText.load ("commentVariable.txt");

    - The right of the People to create Flash movies shall not be infringed. -

  6. #6
    Junior Member
    Join Date
    Apr 2006
    Posts
    7

    NaN appear

    Thanks cancerinform but only show "NaN"in the output window... dont understand.

  7. #7
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Strange. I made a file with a movieclip as button and used that script, which is shown. The trace was 01 without using the datatyping and 1 with datatyping. What is your script and what is your text file? Are you publishing as Flash 8?
    - The right of the People to create Flash movies shall not be infringed. -

  8. #8
    Junior Member
    Join Date
    Mar 2006
    Posts
    5
    how do i make the following code work when I press a button, right now it is set start on load. another thing is for some reason I can't get it to scroll like I have my other text boxes.
    var myStyle:TextField.StyleSheet = new TextField.StyleSheet();
    myStyle.load("sample.css");
    my_txt.styleSheet = myStyle;

    my_txt.multiline= true;
    my_txt.wordWrap = true;
    my_txt.html = true;

    var story:XML = new XML();
    story.ignoreWhite = true;
    story.load("sample.html");
    story.onLoad = function () {
    my_txt.htmlText = story;
    }

  9. #9
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I tested your script with the UIScrollbar and it worked fine for me. How does your XML (HTML) file look like.
    - The right of the People to create Flash movies shall not be infringed. -

  10. #10
    Junior Member
    Join Date
    Apr 2006
    Posts
    7
    Hello, my script is in first action frame:

    lvs = new LoadVars();
    lvs.onLoad = function() {
    p1 = Number(this.variable1);
    p2 = p1+1;
    trace(p2);
    };
    lvs.load("data.txt");

    and my data.txt :

    &variable1=5

    thats all... the result is NaN again...

  11. #11
    Junior Member
    Join Date
    Apr 2006
    Posts
    7
    .....and yes Im publishing in Flash 8

  12. #12
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I tested in a browser with settings access network only and I get NaN. Go to publish - settings and change to access local files only, then it should work (I giuess).
    Last edited by cancerinform; 04-05-2006 at 11:07 AM.
    - The right of the People to create Flash movies shall not be infringed. -

  13. #13
    Junior Member
    Join Date
    Apr 2006
    Posts
    7

    Unhappy

    in my publish settings window appear "Local Playback Security: Acces local files only".. and it don´t work yet.

  14. #14
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    This is strange. When I publish using Flash 8 it actually always works, no matter what is the setting. Only in browsers I found out you need to change settings. Can you post your fla.
    - The right of the People to create Flash movies shall not be infringed. -

  15. #15
    Junior Member
    Join Date
    Apr 2006
    Posts
    7
    this is the fla
    Attached Files Attached Files

  16. #16
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Solved. It was your text file, which gave the problem. You need to write the 2 vars without white space:

    &variable1=5&variable2=9
    - The right of the People to create Flash movies shall not be infringed. -

  17. #17
    Junior Member
    Join Date
    Apr 2006
    Posts
    7
    ITS TRUE!!!!!

    Thank you!

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