A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: The multiplication in as2

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    3

    The multiplication in as2

    hi dears
    when i trace this code :
    PHP Code:
    1*14 
    The answer is 14.
    but this code:
    PHP Code:
    1*014 
    The answer is 12!

    i want use 2th code in to input text field, how fix it?
    please check the source:
    Attached Files Attached Files

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Hers a wacky way of doing it with keeping to your set up !!!
    PHP Code:
    input.restrict "0-9";
    input.maxChars 3;

    var 
    ziro 0;
    var 
    TheText "000";

    total.text TheText;
    input.text TheText;

    goto_btn.onPress = function()
    {
        
    setVerse input.text;
        if (
    setVerse.length 3)
        {
            
    trace("add another number");
        }
        if (
    setVerse 111)
        {
            
    total.text TheText;
            
    input.text TheText;
            
    setVerse ziro;
        }
        else
        {
            if (
    setVerse 99)
            {
                
    setVerse setVerse;
                
    trace(setVerse);
                
    ShowResult();
            }
            if (
    setVerse && setVerse 100)
            {
                
    setVerse setVerse.substring(1input.text.length);
                
    trace(setVerse);
                
    ShowResult();
            }
            if (
    setVerse 10)
            {
                
    setVerse setVerse.substring(2input.text.length);
                
    trace(setVerse);
                
    ShowResult();
            }
        }
    };

    function 
    ShowResult()
    {
        
    Mult setVerse 2;
        
    trace(Mult);
        if (
    Mult 99)
        {
            
    total.text Mult;
        }
        if (
    Mult && Mult 100)
        {
            
    total.text "0" Mult;
        }
        if (
    Mult 9)
        {
            
    total.text "00" Mult;
        }


  3. #3
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Try this:

    PHP Code:
    function format_number(num:String):Number {
        if (
    typeof (num) == "number") {
            return -
    1;
        }
        
    my_str "";
        
    setnum false;
        var 
    my_array num.split("");
        for (var 
    0i<my_array.lengthi++) {
            if (
    my_array[i]>0) {
                
    setnum true;
            }
            if (
    setnum == true) {
                
    my_str my_str+my_array[i];
            }
        }
        return 
    Number(my_str);
    }



    var 
    my_num "014";
    trace(1*format_number(my_num)); 


    poltuda

  4. #4
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Quote Originally Posted by fruitbeard View Post
    Hi,

    Hers a wacky way ...

    thanks dear fruitbeard
    you fix 2*014 but the 1th code'2*14' has error!
    what am i doing to disble ziro in Beginning of word? its mean user cant type ziro in Beginning of word?

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Quote Originally Posted by poltuda View Post
    Try this:

    poltuda
    thanks dear poltuda
    your code is very useful and work very good

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