A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS2: Getting Dynamic Text to display 01, 02, 03...

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    9

    AS2: Getting Dynamic Text to display 01, 02, 03...

    I have a piece of dynamic text displaying the value of particular variable.

    The dynamic text is showing the value accurately, but displays as:
    "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, etc."

    I would like it to display as:
    "01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, etc."

    So if the variable returns a value of 5, I'd like the dynamic text to display "05" instead of "5". This is for purely cosmetic reasons to make my HUD look nice and consistent, and doesn't need to affect any other variables, etc.

    Any ideas on how to accomplish this?

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    HYi,

    You can do something along the lines of

    if(MyNumber < 10){ MyNumber = "0" + MyNumber;}

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Posts
    9
    Yes, perfect! Thanks!

  4. #4
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    PHP Code:
    function zeroFill(strstartend) {
        var 
    fill:String "";
        for (var 
    0i<length(end)-length(start); i++) {
            
    fill += str;
        }
        return (
    fill);
    }

    var 
    num 100;
    var 
    zero "0";

    for (var 
    0i<=numi++) {
        
    trace(zeroFill(zeroinum)+i);


    you could try this.



    marlopax

Tags for this Thread

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