A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Extracting numeric values from concats

  1. #1
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407

    Extracting numeric values from concats

    Yo.

    Is there a way to extract a numeric value from my variable using concatination.


    var i:Number = 1;
    var test1value:Number = 3;

    trace(this["test"+i+"value"]);

    I tried all kinds of tricks but I just can get the string name of the variable instead of the value it holds.
    Anyone?

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    I don't understand the "extract" part.
    Would it be just
    Actionscript Code:
    var i:Number = 1;
    var test1value:Number = 3;

    trace("test"+i+"value");
    If not, provide more details please.

  3. #3
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407
    "extract" is just my fancy name for getting the value the variable holds.

    However,


    trace("test"+i+"value");
    and trace(this["test"+i+"value"]);

    gives the same result, the name of the variable and not the number. Can you think of a way to get the value of the variable out?

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    Actionscript Code:
    var i:Number = 1;
    var test1value:Number = 3;

    trace(this["test"+i+"value"]); // 3
    trace("test"+i+"value"); // test1value

    They don't give the same result.

    The first evaluates the string and gives the value the variable hold: 3 (number)
    The second concatenates the string and gives it: test1value (string)

  5. #5
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, Espa˝a
    Posts
    1,131
    is the variable test1value in your situation actually a property of "this"?

    this["test"+1+"value"] == this.test1value

    try creating the variable in your class variable definitions, or in a dynamic class (or a frame script) specify it as this.test1value=3 instead of scoping it locally with var test1value=3.
    The Strike Agency
    http://www.theStrikeAgency.com

    StrikeSapphire -- The Original Bitcoin Casino
    https://strikesapphire.com
    (not available in the US)

  6. #6
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407
    Doh!
    this["test"+1+"value"] worked.

    and I have that in my snippet and still it doesnt work when I do it.
    So it gotta be something else.
    I guess you get codeblind after a while, I'll keep searching bugs.

    thx.

  7. #7
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003

  8. #8
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    I think there is no revers script to get the variable name.

    var x=100;

    If you provide x, you will get 100.
    But if you provide 100 and ask for x, you will not.

    But there should be something.

    Hope for the best...

    Is that you are talking about?

    Marl÷Pax
    Last edited by marlopax; 10-09-2010 at 05:25 PM.

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