A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [RESOLVED] One small bug can anyone find?

  1. #1
    Member
    Join Date
    Apr 2007
    Posts
    56

    resolved [RESOLVED] One small bug can anyone find?

    One small issue. I cleaned up the code on the buttons but having an issue with stotal value.

    If you compile and run this FLA, select the first then the second then the third choices then deselect in reverse till all are deselected you will see it returns an invalid number , should be zero (0), it also displays 4 decimal places, I have tried to add a function to limit to 2 decimal places but I can't seem to get it to work and even though I need that function not sure if it will fix the bad end value.
    Attached Files Attached Files

  2. #2
    Senior Wabbit
    Join Date
    Jul 2008
    Location
    Winchester, Uk
    Posts
    215
    Ok fixed the bug and added a function for rounding for you.

    This will round to a whole number, rename the dynmamic text var to ttotal, everything else stays as stotal.

    Actionscript Code:
    onEnterFrame = function(){
        ttotal=Math.round(stotal);
    }

    To fix the calculation bug is also really simple.
    add _root.

    Actionscript Code:
    _root.stotal -=20.4;

    Adding that to them all will fix that issue I am tempted to say loop everything
    I have attempted this though failed to get it to work, you can post this for others if you like depends what method you prefer as a beginner maybe best to use your method.
    Actionscript Code:
    stotal=0;
    btn=[q1a,q1b,q1c,q1d,q1e,q1f,q1g,q1h,q1i,q1j];
    sta=[false,false,false,false,false,false,false,false,false,false];
    val=[".12","20.4","13.2","18.4","16",".17",".40",".5","1","1.9"];

    onEnterFrame = function(){
        ttotal=Math.round(stotal);
        for (i=0; i<=btn.length-1; i++){
            btn[i].onRelease=function(){
                if (sta[i] == true){
                    sta[i] = false;
                    _root.stotal -= val[i];
                    trace (val[i]);
                }else{
                    sta[i] = false;
                    _root.stotal += val[i];
                    trace (val[i]);
                }
            }
        }
    }

    Trust my code, and not my english.

  3. #3
    Member
    Join Date
    Apr 2007
    Posts
    56
    that works great how would I get it to display two decimal places?

    Thanks

    I am trying you loop as well I am like a sponge for this stuff right now.

  4. #4
    Senior Wabbit
    Join Date
    Jul 2008
    Location
    Winchester, Uk
    Posts
    215
    Ok for the 2DP you need the following instead

    Actionscript Code:
    ttotal=int((stotal)*100)/100;
    where the 2 100's are states the dp lenght so if both are 10 its 1dp, and if both are 1000 its 3dp, this replaces the old
    ttotal = Math.round(stotal);

    also I forgot to say you can remove all the a1a=0; - a1j=0;
    They have no function

    If you play with the loop make sure you back up the origional as its not a working file at the moment the loop works bit it doesnt get the values from the array atm.

    Also add the stop(); to the top of the actions frame rather than having it seperate.

    I think that should sort you out on the whole

    Trust my code, and not my english.

  5. #5
    Member
    Join Date
    Apr 2007
    Posts
    56
    Ha Ha was just trying to post I figured that out thanks so much

  6. #6
    Member
    Join Date
    Apr 2007
    Posts
    56
    One last question. If you run this and click the 2nd or 4th option they return 1/100 less than actual value. The first has a value of 20.40 and returns 20.39, and the second has a value of 18.40 and returns 18.39. I have a trace in there and it returns the correct value. Strange, rounding function looks correct.
    Attached Files Attached Files

  7. #7
    Senior Wabbit
    Join Date
    Jul 2008
    Location
    Winchester, Uk
    Posts
    215
    try using the math.round function for it so

    Actionscript Code:
    ttotal=(Math.round(stotal*100))/100;

    I think that should work

    Trust my code, and not my english.

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