A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: simple math functions causing undefined errors

  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    3

    simple math functions causing undefined errors

    This seems rather simple but I couldn't find anything on this in a search.

    I am using the math functions such as math.round and math.abs.

    This works fine if I do a test such as: math.round (2.75). The output is fine.

    But when I pass a variable in (this variable has a number value), I get 'undefined' as a result every time. I never had this problem in Flash 4 but Flash MX is killing me!

    I'll provide a code snippet. This is breaking my brain, it seems perfectly fine. When I trace my variable, it outputs a number to two decimal places. So it is number format. But if I run the math functions on it... UNDEFINED!

    Please help.

    The below actionscript uses a changing number value from another movie clip, rounds it to the nearest integer, then goes to a frame with that value in the current movieclip. Simple stuff, but it's not working if I add the math.round function.

    onClipEvent (enterFrame) {
    var a = _root.bank1_mc.bankvalue;
    if (a <= 0) {
    a = 1;
    }
    trace (a);
    a = math.round (a);
    trace (a);
    gotoAndStop(a);
    }

    This is the output:

    0.1
    undefined
    0.2
    undefined
    0.3
    undefined
    0.4
    undefined
    0.5
    undefined
    0.6
    undefined
    0.7
    undefined
    0.8
    undefined
    0.9
    undefined
    1
    undefined
    1.1
    undefined

  2. #2
    Junior Member
    Join Date
    Jun 2006
    Posts
    3
    A further diagnostic modification:

    var b = 2.9485847;
    var c = math.abs(b);

    Trace output gives me
    b = 2.9485847
    c = undefined

    WTF?

  3. #3
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    Math.round not math.round

  4. #4
    Hsalf Muta's Avatar
    Join Date
    Apr 2006
    Posts
    164
    Quote Originally Posted by moagrius
    Math.round not math.round
    Dang you said it before me... oh well...

  5. #5
    Junior Member
    Join Date
    Jun 2006
    Posts
    3
    Curse case-sensitive naming! I'm too used to C++. And Flash 4.

    Thanks.

  6. #6
    Hsalf Muta's Avatar
    Join Date
    Apr 2006
    Posts
    164
    Quote Originally Posted by tanelorn
    Curse case-sensitive naming! I'm too used to C++. And Flash 4.

    Thanks.
    Yup C++ spoils you

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