A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: trying to make a calculator that computes an average

  1. #1
    Junior Member
    Join Date
    Jul 2003
    Location
    UK
    Posts
    6

    trying to make a calculator that computes an average

    Hello, I am trying to make a calculator in Flash MX 2004, with three input fields and an fourth box for the average result. I got some actionscript code whcih I tried to add to a button but it doesn't seem to work for me as I keep getting an error and I don't know if I have put the code into the right area. Could someone please have a look at the fla attached and fix it if possible. The actionscript I used was

    btn.addEventListener(MouseEvent.CLICK, mClick);function mClick(e:MouseEvent):void { var total:String = String(Number(in1.text) + Number(in2.text) + Number(in3.text)); //input instance names = in1, in2, in3 avg.text = String(Number(total) / 3); trace(total);}

    Many thanks
    Attached Files Attached Files

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

    You are using AS3 instead of AS2 or AS1.

    Well you are publishing for AS2 FP 7 anyway.

    PHP Code:
    btn.addEventListener(MouseEvent.CLICKmClick);

    function 
    mClick(e:MouseEvent):void
    {
        var 
    total:Number Number(in1.text) + Number(in2.text) + Number(in3.text);
        
    avg.text String(total 3);

    and you need to create your avg textfield, you need to rename In1 to in1, you might also need to embed yourm fonts.

    You also need to remove the code from your button for AS3. the button componenet you are using is not suitable for AS3 too.

    If all fails then you will need to use AS2/AS1
    Last edited by fruitbeard; 03-06-2015 at 12:18 PM.

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

    The AS2 would be something more like
    PHP Code:
    on (press) {
        
    avg.text = (Number(in1.text) + Number(in2.text) + Number(in3.text)) / 3;

    placed on the button

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