A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Text Files - A Variable Question

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

    Text Files - A Variable Question

    Hey,

    I promise this will be the last thread regarding text files for a while, and no this isnt regarding how you integrate them with Flash, because Ive learnt up to that point

    But I've run into a little problem which is the last of many problems to complete this little assignment.

    My question is, how do you use a variable in flash to tell flash which value to get from the text file. Normally you would say something like:

    dynamicText.text = this.value1;

    But what if you dont know which value is going to be chosen, so you use a variable instead like this:

    code:

    myData= new LoadVars();
    myData.onLoad = function() {
    whichStuff = "stuff3";
    dynamicText.text = this.whichStuff // in other words 'this.stuff3'
    };
    myData.load("text files/dataText.txt");



    The problem is, it returns an undefined value and so doesnt work. Does anyone have any input on this?

  2. #2
    Member
    Join Date
    Sep 2004
    Posts
    89
    A serverside language like php and using GET or POST would do it justice, otherwise you just have to fetch all the data, split it yourself and choose the one you want

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

    I thought I needed all the Php, but I suppose I need more. I was just really hoping there was a way to do something like:

    Instead of this way [which works]
    viewText.text = someText.somevariable2; - which takes a value from a text file

    And do it this way [which doesnt]
    viewText.text = someText[somevariable+number]; - number storing a value of 2

    Hopefully that makes sense.

  4. #4
    Senior Member
    Join Date
    Apr 2005
    Location
    FL, USA
    Posts
    442
    Try a simple test:

    Have a .txt file called "vars.txt" next to (in the same folder as) your .swf.

    In vars.txt, have this:
    &var1=This is variable 1&
    &var2=blah&

    In the first frame of the _root of your flash file, put this:

    Code:
    stop();
    loadVariables("vars.txt" , "");
    onEnterFrame = function() {
    if(input == undefined) {
    disp = "";
    }
    else {
    disp = _root["var"+input];
    }
    }
    Then have an input text field with variable "input" and a dynamic text field with variable "disp". Test the movie. Try typing "1" and "2" into the input text field. Your 2 different .txt variables should appear.
    Is that what you were looking for?
    Last edited by BobJohnson; 03-24-2006 at 10:17 PM.

  5. #5
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Use xml instead of textfiles and you have better control.
    - The right of the People to create Flash movies shall not be infringed. -

  6. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    174
    Osteel,

    I agree with cancerinform... Using text files for variables can be a real headache I would also suggest XML for this type of operation.

    cheers,
    Samuel Agesilas
    http://www.levelofindustry.com

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