dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: eval? mx replacement

  1. #1
    Member
    Join Date
    Jan 2002
    Posts
    48

    eval? mx replacement

    eval() used to work b4 mx but what can be used instead. I wanna display some text which is embedded into a variable loaded from a txt file..

    any ideas?
    The man who can, if not.. trys!

  2. #2
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Post your code! Even with eval in it.

  3. #3
    Member
    Join Date
    Jan 2002
    Posts
    48
    the txt file:
    question_id=U1T2S1Q1
    &question_U1T2S1Q1=Is this the text for question 1?
    &answer_U1T2S1Q1=true
    &answer1=true

    AS:
    question_text = eval("question_"+question_id);
    //should show the text from the above variable
    trace("question_text = " + question_text);
    stop();
    The man who can, if not.. trys!

  4. #4
    Member
    Join Date
    Jan 2002
    Posts
    48
    people say instead of eval use this["blar" + blar] but that doesn't work, im pulling my hair out here.

    do any1 understand where im coming from and what my problem is??
    The man who can, if not.. trys!

  5. #5
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Content of "question.txt":

    question_id=U1T2S1Q1&question_U1T2S1Q1=Is this the text for question 1?&answer_U1T2S1Q1=true&answer1=true



    Code:
    loadVarsText = new loadVars();
    loadVarsText.load("question.txt"); 
    loadVarsText.onLoad = function (success){
    	if (success){
    	    trace ("Done loading!");
    	    trace (this["question_id"]);
    	    question_text = this["question_id"];
    	    trace("question_text = " + question_text);
             } else {
                trace ("Not loaded!");
    	}
    };
    
    stop();
    -----------------------------


    trace("question_text = " + question_text);
    stop();

    ...Would work on the following frame(s), but not on the same frame as the one reading in the variables.

  6. #6
    Member
    Join Date
    Jan 2002
    Posts
    48
    good answer but that returns:

    U1T2S1Q1 as the string

    what im after is the text within the variable question_U1T2S1Q1

    as soon as i add this["question" +"question_id"]it doesnt work...
    The man who can, if not.. trys!

  7. #7
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    Code:
    question_text = this["question_" + this.question_id];

  8. #8
    Member
    Join Date
    Jan 2002
    Posts
    48
    i tried that, but it didnt work

    The man who can, if not.. trys!

  9. #9
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    But this does:

    Code:
    loadVarsText = new loadVars();
    loadVarsText.load("question.txt"); 
    loadVarsText.onLoad = function (success){
    	if (success){
    		trace ("Done loading!");
    		trace (this["question_id"]);
    		temp_text = "question_"+this["question_id"];
    		trace(temp_text);
    		question_text = this[temp_text];
    		trace("question_text = " + question_text);
        } else {
            trace ("Not loaded!");
    	}
    };
    stop();

  10. #10
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    you tried it?
    Code:
    _loadvars = new LoadVars();
    _loadvars.onLoad = function(success) {
    	if (success) {
    		trace("Done loading!");
    		trace(this["question_id"]);
    		question_text = this["question_" + this.question_id];
    		trace("question_text = " + question_text);
    	} else {
    		trace("Not loaded!");
    	}
    };
    _loadvars.load("question.txt");
    stop();
    Attached Files Attached Files

  11. #11
    Member
    Join Date
    Jan 2002
    Posts
    48
    gSOLO_01 you are the MAN!!!!!!!!!!!!!!!

    give your a big pat on the back, you have saved me going bald!

    Thanz your attachment worked.




    question though why have you loaded the variables at the end??

    ps oldnewbie yours worked aswell, big up urself
    Last edited by gazman99; 03-18-2003 at 01:10 PM.
    The man who can, if not.. trys!

  12. #12
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    I always put the load at the end... It just makes sense to me to do it that way; always define the funtion first. Tell it what to do when an event happens before the event happans.

    ... but looking at all of the documentation and stuff at Macromedia, they do it the other way so I guess it doesn't matter...

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