6 Replies Latest reply on Mar 28, 2012 10:06 AM by Flex harUI

    No such variable: FlexGlobals

    rexdtripod Level 1

      Have upgraded to FlashBuilder with Flex 4.5 and am trying to pass parameters into swf via prescription at:

       

      http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html

       

      Flex doesn't seem to know what FlexGlobals is though.  I'm copying and pasting the sample code from the bottom of the page at the link above (in the section labeled "Accessing the flashVars properties").  The code seems to have the proper namespace declarations and library imports.

       

      The compiler never complains.  But when I run I get no variables.  If I set a watch on FlexGlobals it responds "no such variable".

       

      The point of the example is to see variables passed into the swf.  They never make it though.

       

      What could be wrong?

        • 1. Re: No such variable: FlexGlobals
          Amy Blankenship Level 4

          I don't think watch expressions can watch Class-level/static (not instance) variables.  Try this:

           

           

          var obj:Object = FlexGlobals.topLevelApplication.parameters;

           

          Then put a watch on Object, or just set a break point at the next line and inspect its value.

           

          HTH;

           

          Amy

          1 person found this helpful
          • 2. Re: No such variable: FlexGlobals
            rexdtripod Level 1

            Thanks for the response.

             

            No dice.  obj just comes up empty. Param variables come up null as well.

             

            Code is at that link I posted in this thread.  Are you able to compile and run successfully?  Would tell me if there is something wrong with my IDE or project configuration.

             

            Thanks

             

            P.S.  Side note.  My old Flex 3.5 code does work properly.  You can set a watch on the following:

             

            mx.core.Application.application.parameters

             

            Have been passing parameters like that successfully for some time.  Only recently upgraded to FlashBuilder and SDK 4.5.

            • 3. Re: No such variable: FlexGlobals
              Amy Blankenship Level 4

              I've used FlexGlobals.topLevelApplication.parameters successfully in Flex 4 before, though not that exact code.  You could potentially also try something like

               

              var app:Object = FlexGlobals.topLevelApplication

               

              and inspect its properties.

              • 4. Re: No such variable: FlexGlobals
                rexdtripod Level 1

                Thanks.

                 

                Yes.  For some reason that works.  Must create an object first.

                 


                So to summarize, this works (first time I implemented I screwed up but corrected and this does work):

                 

                var obj:Object = FlexGlobals.topLevelApplication.parameters;

                firstName = obj.firstName;

                 

                 

                This does not work:

                 

                firstName= FlexGlobals.topLevelApplication.parameters.firstName;

                 

                 

                Weird but, OK, I'll go with it.

                 

                Thanks much.

                • 5. Re: No such variable: FlexGlobals
                  rexdtripod Level 1

                  Actually this is intermittent for me in Flex 4.6.  The following code produces "No such variable: FlexGlobals" in debug mode (see attached image).  Trying to figure out the pattern here.  Sometimes when it says "No such variable: FlexGlobals", parameters actually come through.

                   

                  Uggh...

                   

                   

                  <?xml version="1.0" encoding="utf-8"?>

                  <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                   xmlns:s="library://ns.adobe.com/flex/spark"

                                                   xmlns:mx="library://ns.adobe.com/flex/mx"

                                                   preinitialize="application1_preinitializeHandler(event)">

                            <fx:Script>

                                      <![CDATA[

                                                import mx.core.FlexGlobals;

                                                import mx.events.FlexEvent;

                   

                                                protected function application1_preinitializeHandler(event:FlexEvent):void

                                                {

                                                          // TODO Auto-generated method stub

                                                          var appParams:Object = FlexGlobals.topLevelApplication.parameters;

                                                }

                   

                                      ]]>

                            </fx:Script>

                            <fx:Declarations>

                                      <!-- Place non-visual elements (e.g., services, value objects) here -->

                            </fx:Declarations>

                  </s:Application>

                   

                  FlexGlobals.jpg

                   

                  Message was edited by: rexdtripod.

                  • 6. Re: No such variable: FlexGlobals
                    Flex harUI Adobe Employee

                    The expressions window cannot resolve classes like that.  Doesn’t the varaibles window have it right?

                     

                    IIRC, in the expressions window, I try to find enough context to resolve a string to a class.  Because the this pointer is the application in this case, you can try an expression like:

                     

                        systemManager.getDefinitionByName(“mx.core.FlexGlobals”).topLevelApplication