0

I've got a component written for my app by a third party developer and am trying to integrate it, but I've found a bug that seems like it's either a compiler bug, or there's something with how Flex and static variables work that I wasn't aware of.

Basically, I have this:

public class ModeChangeController {
    public static const DISPLAY_MODE:String = "DisplayMode";

}


public class Events {       
    public static const DISPLAY_MODE:String = "DisplayMode";

    public static function myStaticFunction( viewState:String = null):void {
        //Empty
    }
}



<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer /*snip*/ >

    <fx:Script><![CDATA[
        import mypackage.sub1.ModeChangeController;
        import mypackage.sub2.Events;

        private function showInitialView():void {
            // Variant 1
            Events.myStaticFunction( Events.DISPLAY_MODE);

            // Variant 2
            Events.myStaticFunction( ModeChangeController.DISPLAY_MODE);
        }
    ]]></fx:Script>
}    

If I use //V2 (i.e. comment out V1), a bug occurs at the startup of the application (some TextFields are uneditable and contains no text), but with //V1 and not V2, it works fine. If I comment out both, that also works fine (I don't get the TextField bug).

It took me a while to figure out that it was that static const String that was causing the issue, but I'm still not sure why or if there's something I can do about it except for just moving the DISPLAY_MODE to Events (which is what I've done at the moment, but it's not a particularly nice solution).

There are no errors in the log. The order of the includes in my BorderContainer code doesn't matter. I've googled for "as3/flex static initialization order" but haven't found anything.

Does anyone know what the problem is?

Clarification: showInitialView() never gets called. It doesn't get there before the other bug shows up. Just having the V2 line there causes the problem.

Update: I've fixed my problem with the TextInput strings not showing: Turns out that adding the component caused the Tahoma font to not show up. However, setting the font-weight to bold fixed that problem, or switching to Arial. With that said, the original question still stands, because when I ran it without V2, it found Tahoma with normal font-weight.

3
  • When is showInitialVie executed? What happens if you use the debugger and step through that line? Since myStaticFunction does nothing [as per your code] I find it very hard to believe that either of those lines would cause the app to be initialized differently. Unless you didn't have a debug player installed and you were missing a runtime error May 10, 2011 at 14:04
  • Added a clarification with regards to your comment.
    – Srekel
    May 10, 2011 at 15:08
  • Sounds like you have a problem w/ embedded fonts; which has nothing to do w/ Static Variables. May 10, 2011 at 18:07

1 Answer 1

0

It's not the static string. I tested it myself without a problem. I was skeptical of your issue since the flash static vars would get created when the application is loaded no matter what and the variable would be available.

I believe the problem has nothing to do with the static var but with something else causing an error. It seems that you don't have a version of Flash Player debug by your description. Get it, debug your application line by line and see what the problem is.

5
  • Sorry, I should have mentioned that that code is a very simplified version of what it looks like in the component. I am able to debug the code (through Eclipse/FB4) but "showInitialView" never gets called - see my clarification.
    – Srekel
    May 10, 2011 at 15:05
  • Your clarification makes no sense, if you're debugging and there is an error, where is it? If it's failing silently, what are you doing to make it? Just having a line of code that doesn't run not in your application isn't going to cause an error, that is unless you have a static var/function somewhere that is causing an error. You're blaming this on the static var where the static var is fine. Something else in your code is the culprit.
    – J_A_X
    May 10, 2011 at 15:12
  • Updated the question with some info. I know it doesn't make any sense, that's why I'm asking. :) And yes, having a line of code that doesn't run DID cause an error, whether or not it makes sense. ;)
    – Srekel
    May 10, 2011 at 16:18
  • The question doesn't stand because you're withdrawing information about your own code and I can isolate to say that your original accusation of static vars not properly instantiating is false. This is not the Flash Player's or the compiler's fault, it's something in your code.
    – J_A_X
    May 10, 2011 at 16:28
  • I'll give you that it's not necessarily about the order of static variable initialization, but that is the only conclusion that makes sense to me. If it is a problem with something in the rest of the code, I'm wondering how/why it only shows when I remove the call to myStaticFunction with that particular static variable as a parameter. Sorry I can't include more of the source but the files are fairly large in addition to being property of the company.
    – Srekel
    May 10, 2011 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.