dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: can flash mx do this?

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    126

    can flash mx do this?

    hi i got a question i do not know if it will work in flash.

    I know how to let flash calculate but i was wondering if it can be done else.

    here's what i have.

    3 textfields: firstNumber, secondNumber, Result.

    At the moment i have a button that will caculate when pressed and that works, but i was wondering if it can in someway auto calculate when entered a number ??


    like when i place 20 in firstNumber textfield the result is 20
    and if i enter 40 in the secondNumber textfield the result textfield would show 60 right away ?! instead of using a button ?

    I really don't know if its possible, i only know that i would like it to act the same way as when i would do in microsoft excel.
    If you give an action to a field there it will change the result right away when new number is placed.

    thnx in advange...

    Assenoost

  2. #2
    Junior Member scudsucker's Avatar
    Join Date
    Feb 2003
    Location
    Cape Town, RSA
    Posts
    1,509
    If you were to attach the following code to any movieclip on the stage, then the textfields would display as you wish. If you dont have a movie on stage, create a blank one.

    onClipEvent(enterFrame) {
    _root.Result=_root.firstNumber+_root.secondNumber;
    // optional extra...
    if(isNAN(_root.result)){
    _root.Result="Cannot Display";
    }
    }
    Hariyemadzisawira nhaka yedu! Down the SCUD and win!
    I'm too lazy to read Private Messages.

  3. #3
    Senior Member
    Join Date
    Jan 2001
    Posts
    126
    you have a simple fla for this ?! cause i do try the code but it won't display the changes directly on entering the numbers

    thnx advange

    assenoost

  4. #4
    Junior Member scudsucker's Avatar
    Join Date
    Feb 2003
    Location
    Cape Town, RSA
    Posts
    1,509
    Ok, with a small variation on the code- I forgot that the simple + would concatenate the variables...

    onClipEvent(enterFrame) {
    _root.Result=Number(_root.firstNumber) + Number(_root.secondNumber);
    // optional extra...
    if(isNAN(_root.result)){
    _root.Result="Cannot Display";
    }
    }

    Attached is the .fla
    Hariyemadzisawira nhaka yedu! Down the SCUD and win!
    I'm too lazy to read Private Messages.

  5. #5
    Senior Member
    Join Date
    Jan 2001
    Posts
    126
    that works
    Thank you so much

    got one small problem though... i created another fla to test it and tried to do some extra

    i got 5 textfields. a,b,c,d,result
    ok now a starts of at being 501

    then i count b,c, d to get the result. that works...
    i also want it to auto set the new total so that would be a - result is new. it does do that but then the number keeps going down to zero and then moving back up..

    see the attached fla

    hope there is a solution for this..

    thnx in advange.

    assenoost
    Attached Files Attached Files

  6. #6
    Junior Member scudsucker's Avatar
    Join Date
    Feb 2003
    Location
    Cape Town, RSA
    Posts
    1,509
    OK, I think the problem lies in that you have got the field 'a' being calculated by minusing the Result value from its own value in the onClipEvent(enterFrame) handler, so that is 12 times/second.

    You need to calculate this value only when the Result changes... so put in a variable named oldValue, then test to see if Result==oldValue, and if not, calculate the new value of field 'a', and reset oldValue to the new value of Result.

    Hope that makes sense!
    Hariyemadzisawira nhaka yedu! Down the SCUD and win!
    I'm too lazy to read Private Messages.

  7. #7
    Senior Member
    Join Date
    Jan 2001
    Posts
    126
    first of all thanx for the fast replies
    this is really helpfull..

    i downloaded the fla and it looks like it works..

    but then i noticed that it does not calculate correct.

    when entered 100 in the fisrt input field it turns the above score to 390 instead of 401 ? any idea why it does that

    greetz...

    Assenoost

  8. #8
    Junior Member scudsucker's Avatar
    Join Date
    Feb 2003
    Location
    Cape Town, RSA
    Posts
    1,509
    Try replacing all the 'Number' with 'parseFloat' then it does its math correctly!

    Sorry for that...
    Hariyemadzisawira nhaka yedu! Down the SCUD and win!
    I'm too lazy to read Private Messages.

  9. #9
    Senior Member
    Join Date
    Jan 2001
    Posts
    126
    One step closer but it doesnot calculate correct when entering a number in the second or third inputfield

    When i enter 1 at first input it changes correctly to 500 but when i go to second inputfield and enter 20 it changes to 476 instead of 480

    thanx for your patience

    Assenoost

  10. #10
    Junior Member scudsucker's Avatar
    Join Date
    Feb 2003
    Location
    Cape Town, RSA
    Posts
    1,509
    The reason for this is that I set the score to change every time that one of the fields change... so when you enter 1 in the first field, it calculates 501-1=500;
    then when you enter 20 in the second filed, it first calculates

    500-(2+1)=497;

    and then

    497-(20+1)=476;

    The extra 1 in each calculation is the first field being added each time.

    To avoid this, you will have to calculate only when the field's value is complete, possible using an onKillfocus for each text field. Or else, a button that can be pressed ( though thats what you originally wanted to avoid ) or a invisible button that could catch a tab or enter key-press.

    Replace the if statement with this:

    _root.Count1.onKillFocus = function (newFocus) {
    _root.a=parseFloat(_root.a) - parseFloat(_root.result);
    }
    _root.Count2.onKillFocus = function (newFocus) {
    _root.a=parseFloat(_root.a) - parseFloat(_root.result);
    }
    _root.Count3.onKillFocus = function (newFocus) {
    _root.a=parseFloat(_root.a) - parseFloat(_root.result);
    }

    Its still not perfect, but better!
    Hariyemadzisawira nhaka yedu! Down the SCUD and win!
    I'm too lazy to read Private Messages.

  11. #11
    Senior Member
    Join Date
    Jan 2001
    Posts
    126
    yep this is allready much better. Only problem is that it does the minus off all 3 counts three times...

    seems this works though

    _root.Count1.onKillFocus = function (newFocus) {
    _root.a=parseFloat(_root.a) - parseFloat(_root.b);
    }
    _root.Count2.onKillFocus = function (newFocus) {
    _root.a=parseFloat(_root.a) - parseFloat(_root.c);
    }
    _root.Count3.onKillFocus = function (newFocus) {
    _root.a=parseFloat(_root.a) - parseFloat(_root.d);
    }


    thank you so much for your help and time

    greetings

    assenoost

  12. #12
    I have an icon and U dont! johnwun's Avatar
    Join Date
    Nov 2000
    Location
    Santa Cruz, CA
    Posts
    258
    Then you could save a lot of processor time and do it with MX's onChanged function...
    Attached Files Attached Files
    [a.fun>b.fun ? trace("do(a)") : trace("do(b)");

    wundes.com

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