A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Conversion Calculator

  1. #1
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713

    Conversion Calculator

    http://www.diversioncentral.com/calc...nversions.html

    I was thinking of putting this on the koolexchange. If you see a problem or bug, please let me know.
    Any programming language is at its best before it is implemented and used.

  2. #2
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Cool.

    Only suggestion I have is to restrict the input fields to numbers only. Great job Tim

  3. #3
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Quote Originally Posted by Chris_Seahorn
    Cool.

    Only suggestion I have is to restrict the input fields to numbers only. Great job Tim
    I was looking for something consumer oriented. What problem did you find? Why do you say "numbers only"?
    Any programming language is at its best before it is implemented and used.

  4. #4
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    If they enter a letter the conversion will return "NaN" (not a number). It's not a big deal and doesn't affect function so forget I mentioned

  5. #5
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    See what you mean Chris. This is why I posted. Looking for all the mistakes. I will repost when done. This application whould be worthless without your help.
    Any programming language is at its best before it is implemented and used.

  6. #6
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Quote Originally Posted by tmoore935
    See what you mean Chris. This is why I posted. Looking for all the mistakes. I will repost when done. This application whould be worthless without your help.
    No way man. That baby is all you. Really useful too. I would definitely submit that if I were you

  7. #7
    That web bloke Stoke Laurie's Avatar
    Join Date
    Jan 2006
    Location
    England
    Posts
    869
    Great idea, could use something like that on my sites as a "stcky resource" or logo it up as a download as a projector with the site name on. Great thinking, please put in the exchange.

  8. #8
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Tmoore You might either not allow the result field to be edited, OR consider allowing one to do both like Gallon to Liter and liter to gallon and use the event onChanged to know wich direction to do the calculation.

    Here's a code snippet to consider
    Code:
    txt1.restrict = "0-9\u002E";
    txt2.restrict = "0-9\u002E";
    txt1.onChanged=function(){
    if (txt1.text!=""){
       txt2.text=txt1.text*3.7853
          }
       }
       
    txt2.onChanged=function(){
    if(txt2.text!=""){
       txt1.text=txt2.text*.2642
       }
    
       }
    Put two text boxes on the stage txt1 and txt2 and try this. This way you can only enter 0-9 and the '.' and it only calculates if the textbox is not NULL to avoid the NaN.

    And which ever box you edit the other shows the calulated value

  9. #9

  10. #10
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    I could change this before I submit. It would also reduce the amount of buttons.

    But I do not understand the

    txt1.restrict = "0-9\u002E";
    Any programming language is at its best before it is implemented and used.

  11. #11
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    That is the unicode escape equivilent of "." (period).

    You could also use:

    txt1_txt.restrict = "0-9 .";

    or

    txt1_txt.restrict = "0-9, .";

    etc

  12. #12
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Ok. I guess the forwardslash made it look like an equation or something.
    Thanks all.
    Any programming language is at its best before it is implemented and used.

  13. #13
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Hello, I was able to get everything to work as Blanius suggested but I have a problem with temps. This is because the answer is sometimes negative and I cannot get any display unless an answer is positive.
    And what is the unicode for a math minus sign? I went online to look and I found 2212 as a unicode, but it still does not let me enter a minus sign. The same in Flash 8.
    Any ideas.

    This code works in flash 8 but not koolmoves.
    txt1.restrict = "0-9 - .";
    txt2.restrict = "0-9 - .";

    txt1.onChanged=function(){
    //to get F
    if (txt1.text!=""){
    t = txt1.text;
    b = ((5/9)*(t - 32));
    txt2.text = b;
    }
    }

    txt2.onChanged=function(){
    //to get C
    if(txt2.text!=""){
    t = txt2.text;
    b = ((9/5)*t) + 32;
    txt1.text = b;
    }

    }
    Any programming language is at its best before it is implemented and used.

  14. #14
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    002D is ASCII for -

    Try
    txt1.restrict = "0-9\u002E\u002d";

  15. #15
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Quote Originally Posted by blanius
    002D is ASCII for -

    Try
    txt1.restrict = "0-9\u002E\u002d";
    I tried that already which is why I went online to unicode.org. It also does not work with Flash 8.
    I can always omit the txt.restrict for this one particular equation, but i cannot get the answers when they are less then zero. This has me stumped. Which means its something simple.
    Any programming language is at its best before it is implemented and used.

  16. #16
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ok Tom You made me go look at the Flash 8 docs... LOL

    txt1.restrict = " 0-9\u002E\\-";

  17. #17
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    restrict (TextField.restrict property)

    public restrict : String

    Indicates the set of characters that a user may enter into the text field. If the value of the restrict property is null, you can enter any character. If the value of the restrict property is an empty string, you cannot enter any character. If the value of the restrict property is a string of characters, you can enter only characters in the string into the text field. The string is scanned from left to right. A range may be specified using the dash (-). This only restricts user interaction; a script may put any text into the text field. This property does not synchronize with the Embed Font Outlines check boxes in the Property inspector.

    If the string begins with ^, all characters are initially accepted and succeeding characters in the string are excluded from the set of accepted characters. If the string does not begin with ^, no characters are initially accepted and succeeding characters in the string are included in the set of accepted characters.

    Availability: ActionScript 1.0; Flash Player 6
    Example

    The following example allows only uppercase characters, spaces, and numbers to be entered into a text field:

    my_txt.restrict = "A-Z 0-9";

    The following example includes all characters, but excludes lowercase letters:

    my_txt.restrict = "^a-z";

    You can use a backslash to enter a ^ or - verbatim. The accepted backslash sequences are \-, \^ or \\. The backslash must be an actual character in the string, so when specified in ActionScript, a double backslash must be used. For example, the following code includes only the dash (-) and caret (^):

    my_txt.restrict = "\\-\\^";

    The ^ may be used anywhere in the string to toggle between including characters and excluding characters. The following code includes only uppercase letters, but excludes the uppercase letter Q:

    my_txt.restrict = "A-Z^Q";

    You can use the \u escape sequence to construct restrict strings. The following code includes only the characters from ASCII 32 (space) to ASCII 126 (tilde).

    my_txt.restrict = "\u0020-\u007E";

  18. #18
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Ok, this works, but with + it doesnt need the forward slash. Thank you. I did read what you had posted but ignored the slashes.

    Still, why does koolmoves have this problem with getting numbers less then 0 to appear?
    Any programming language is at its best before it is implemented and used.

  19. #19
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Quote Originally Posted by tmoore935
    Ok, this works, but with + it doesnt need the forward slash. Thank you. I did read what you had posted but ignored the slashes.

    Still, why does koolmoves have this problem with getting numbers less then 0 to appear?
    Glad that helped, can't answer for KM, I love that movie.

    Like this avatar better. (yes that's me)
    Last edited by blanius; 11-17-2006 at 11:34 PM.

  20. #20
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Like this avatar better. (yes that's me)
    Yea, but the kids not so ugly.
    Whoops..Thats why I don't post pics of myself...nevermind
    Really though. Thanks for the help
    Any programming language is at its best before it is implemented and used.

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