A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: tracing the variable name?

  1. #1
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991

    tracing the variable name?

    Hi

    i'm trying to create a function where when i pass a variable to it it displays both the var and the value...

    like:

    sex = "yes please";

    checker = function(var){
    trace([var] +"=" + var);
    }


    checker(sex);

    //should output "sex=yes please"

    but ofcourse the above function wont output the variable name.. how do i accomplish what i want? any ideas?

    regards

    TJ

  2. #2
    Senior Member
    Join Date
    Jun 2003
    Location
    Kent, WA
    Posts
    536
    I don't believe that's possible unless you explicitly define a string of the variable name. When you compile the actual names of the variables get compiled away (converted into memory addresses), so that information doesn't even exist.

    I think this is the closest you'll get:

    Code:
    var sex:String = "yes please";
    checker("sex", sex);
    
    function checker(name:String, value:String)
    {
        trace(name+" = "+value);
    }

  3. #3
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    yah well that's the thing haha i want my function to be as simple as possible. it's actually a debugger for variables so i can easily check if the said variable has the expected data...

    so if i have

    name="tea"

    and i call


    checker(name);

    should output
    "name=tea"

    .. i know, im just bein lazy hehe. thought it was possible though as it's possible in php hehe

    thanks though

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