Gaming Your Way

May contain nuts.

Thank you for wasting my time

This is going to be a rant post - yeah!

If your following us on twitter, you might have noticed my tasks for yesterday:

"Quick update on the CMS then coding on the first unity game"

Well, I didn't get to the unity game part, thanks to some weird flash (bug) that wasted 5 fucking hours of my time and still is inresolved. Here's a quick rundown:

For our new german site I wrote a simple flash based menu/header which reads in an XMl and takes two params. The xml reading was all done, but I needed to pass the params from the asp.net page to the header. I decided to use loaderInfo.params for the sake of a quick and dirty solution and then it all went down the drain ...

Testing params in THE IDE doesn't work, so I published a HTML page withit (I did mention that so far the menu worked very well?).
But opening the file locally in FF 3.0.8 did do nothing ... no menu generated from xml, it just showed the background shape.

OK, lets try in IE (6, 7, and 8) and it worked just fine, params passed, menu displayed.
Chrome worked, too, same with Opera...

FUCK! Why doesn't it work in FF?

Next thing I tried was to upload the whole lot and tried it from the server - and look it worked in FF, too. ONE FUCKIN TIME! After the file was chached it quit working just like it did offline. (All other browsers still worked just fine).

FUCK!

K, let's add some outputs to the loading process - and viola the problem was quite easy to nail down ...

Here's a stripped down version of the code: (I used a document class and a single frame with a few vector shapes on it and some textfields with an embeded font only)

Code:

/**
* ...
* @author nGFX
* @version 1.0
*/


package {
    
    // skipped imports

    public class Preloader extends Sprite {
        
        public function Preloader() {
            
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.showDefaultContextMenu = false;
            stage.quality = StageQuality.HIGH;
            
            trace("init preloader");

            this.loaderInfo.addEventListener(Event.INIT, this.initDisplay);
            this.loaderInfo.addEventListener(Event.COMPLETE, this.initApplication);
            this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, this.showProgress);            
            
        }
        
        private function initDisplay(e:Event):void {

            trace("init display");
            
        }
        
        private function showProgress (eProgress:ProgressEvent):void {
            
            var fPercent:Number = Math.round((eProgress.bytesLoaded / eProgress.bytesTotal ) * 100 );
            
            trace("Loading: " + fPercent.toString());
            
        }

        private function initApplication (e:Event):void {
            
            trace("init application");
            
            this.loaderInfo.removeEventListener(Event.INIT, this.initDisplay);
            this.loaderInfo.removeEventListener(Event.COMPLETE, this.initApplication);
            this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, showProgress);
            
            trace("loading language")
            Locale.loadLanguageXML("de", onLanguageFileLoaded);
            
        }
        
        private function onLanguageFileLoaded (bLoaded:Boolean):void {
            
            trace("language done")
                    
            this.initMenu();
                        
        }
        
        private function initMenu ():void {
            
            // some code here

        }
        
    }
    
}



As you can see there's no magic added to that code.

Running the swf through a a html page using FF showed the following:
- init preloader
- init display

... and nothing more ....

Comments (6) -

  • Michael J Williams

    4/8/2009 1:03:40 PM |

    Did you fix this in the end?

    I saw this problem recently and it really had me stumped. I think the problem is that, because the file is so small (and cached!), the loaderInfo fires off the ProgressEvent.PROGESS and Event.COMPLETE events before the SWF is actually initialised. (Or perhaps the events are never fired off in this case, I'm not sure exactly how Flash handles it.)

    In that case it should be possible to check loaderInfo.bytesLoaded against loaderInfo.bytesTotal in the constructor and just skip straight to initApplication() if they match.

    Does that sound right?

  • nGFX

    4/8/2009 4:33:23 PM |

    I didn't really fix it, I'm affraid. Because the file is so small I used flash's timeline to get over that problem (oh and I just see that somehow the rest of the post got messed).

    I ripped out the progress watching code altogether.

    Anyway, my sollution was that I placed the "initApplication" call on the timeline (frame 3) so it is fired when flash has loaded that one in...

    What pissed me most was the fact that it worked in the IDE and in IE ...

    nGFX

  • Terry

    4/8/2009 9:33:25 PM |

    Oh man, I totally had this problem with Don't Look Back (or something very similar) meaning that the game wouldn't start for a lot of people using old versions of IE. It turned out that ProgressEvent.PROGRESS just doesn't work for some people. Took me forever to track it down, and I don't really understand why it was happening in the first place. I eventually fixed it by just using an enterframe event instead...

  • Scarybug

    4/9/2009 7:02:46 PM |

    Terry, that explains some of the problems I've been having with ProgressEvent.PROGRESS. I thought I was doing something wrong for so long, and also decided to give up on it and use Event.ENTER_FRAME.

  • nGFX

    4/10/2009 9:50:31 AM |

    Ha! and I thought it was only me. Thank you Adobe, for that. And also thank you to Adobe for that it's cheaper to buy a new software in the pro version (Unity) than upgrading ... CS3 to a buggy piece of 0.5 shit (CS4) ...

    nGFX

  • nGFX

    4/10/2009 12:26:36 PM |

    And another one goes to Adobe ... for some unexpected reason I can't create PDF files anymore with my CS3 Complete Acrobat! Joy!

    Fuck!

    nGFX

Comments are closed