Flashing away

Well, the Flash work is nearly finished. I thought I'd escaped any screwy bugs this time round, but in the past 48 hours I've hit two new ones. I thought I'd write them up here in case it helps anyone else.

  1. A curious arrangement of text fields, movieclips and buttons caused a text field to magically regain the input focus just after it lost it. In my case I was hiding the text field straight after, and this resulted in button clicks failing.

    The only solution I could find was to use Selection.setFocus to manually set the focus to an empty text field after the first input box had lost it. I first tried putting the setFocus call in the onKillFocus method of the text field, but it just triggered the onKillFocus method over and over again in an infinite loop, so don't do that - call setFocus from the code that causes (or is triggered by) the first onKillFocus. Kay?

    Update: This was along the right tracks, but it appears that it was a problem with the FocusManager component. Fixed with:

    function fixFocus(button) {
        button._focusrect = false;
        Selection.setFocus(button);
    }
    

    I call that from within every onRelease function; just stick fixFocus(this) at the top.

  2. An old bug has resurfaced somewhere that it really shouldn't be causing any problems. In essence, ActionScript seems to think that 1 - 1 = -2.8421709430404e-14. I'd guess this is due to floating point rounding error, but both the numbers causing my problem here appear to be integers... Anyway, simple to fix this time, just used Math.floor().

As I say, they're fixed now, but I really wish ActionScript didn't have these problems. I have enough work to do without wasting days tracking down bugs that aren't my fault.

Comments

Setting the default (only?) numerical var type to be a float is beyond idiotic. That said, I'm not sure why "1" would be approximated as a float, seeing as it can be represented exactly in binary. Maybe they're adding 33 and 6/17 to every number before they do any calculation on it...

They must be doing something stupid. Even if there was a tiny little bit of rounding error somewhere along the line, if it prints it out as 2.45673, it should treat it like it was 2.45673!

Leave a comment