5 Replies Latest reply on Feb 19, 2012 6:39 PM by theforwardway

    Problem overriding a conditional compilation definition

    cheungpat

      To demonstrate the problem I have, this is a simplified Flex 4 application and I saved it as Main.mxml:

       

       

       

      <?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">
          <fx:Script>
          <![CDATA[
          [Bindable]
          private var debug:Boolean = CONFIG::DEBUGGING;
          [Bindable]
          private var hostname:String = CONFIG::HOSTNAME;
          ]]>
          </fx:Script>
          <s:layout>
              <s:VerticalLayout paddingLeft="20" paddingTop="20"/>
          </s:layout>
          <s:Label text="{debug}" />
          <s:Label text="{hostname}" />
      </s:Application>
      

       

      And a flex-config file saved as Main-config.xml in the same directory as Main.mxml:

       

       

      <flex-config>
          <compiler>
              <define>
                  <name>CONFIG::HOSTNAME</name>
                  <value>"127.0.0.1"</value>
              </define>
              <define>
                  <name>CONFIG::DEBUGGING</name>
                  <value>true</value>
              </define>
          </compiler>
      </flex-config>
      

       

      According to the documentation, mxmlc reads Main-config.xml automatically, which is true:

       

      $ mxmlc Main.mxml Loading configuration file /Library/Frameworks/Flex.framework/Versions/4.0.0.14159/frameworks/flex-config.xml Loading configuration file /Users/me/playground/flex/Main-config.xml /Users/me/playground/flex/Main.swf (39418 bytes)

       

      So far so good. But then I got a "Access of undefined property" error with mxmlc when I try to override a conditional compilation definition in the command line, which according to the documentation should have a higher precedence than the flex-config file.

       

      $ mxmlc -define=CONFIG::DEBUGGING,false Main.mxml
      Loading configuration file /Library/Frameworks/Flex.framework/Versions/4.0.0.14159/frameworks/flex-config.xml
      Loading configuration file /Users/me/playground/flex/Main-config.xml
      /Users/me/playground/flex/Main.mxml(10):  Error: Access of undefined property HOSTNAME.
      
           private var hostname:String = CONFIG::HOSTNAME;
      
      
      

       

      If I run mxmlc with -dump-config=dump.xml and examine the dumped flex-config file, only CONFIG::DEBUGGING while CONFIG:HOSTNAME is missing. It seems that when I specify a definition in the command line, mxmlc forgets that I have specified other definitions in Main-config.xml.

       

      What did I do wrong?

        • 1. Re: Problem overriding a conditional compilation definition
          Vikash.kumar29

           

          <flex-config>
              <compiler>
                  <define>
                      <name>CONFIG::HOSTNAME</name>
                      <value>127.0.0.1</value>
                  </define>
                  <define>
                      <name>CONFIG::DEBUGGING</name>
                      <value>true</value>
                  </define>
              </compiler>
          </flex-config>
          

           


          In the above code, I found an attribute missing called append=true which override the previous define value set by the xml.

          indeed you can use the following code:

           

          <flex-config>
              <compiler>
                  <define append="true">
                      <name>CONFIG::HOSTNAME</name>
                      <value>127.0.0.1</value>
                  </define>
                  <define append="true">
                      <name>CONFIG::DEBUGGING</name>
                      <value>true</value>
                  </define>
              </compiler>
          </flex-config>

          Hope this helps you in solving your problem.

           

          Cheers

          -Vikash

          • 2. Re: Problem overriding a conditional compilation definition
            cheungpat Level 1

            Tried using append="true" attribute in Main-config.xml for both <define>, but it doesn't work for me.

             

            $ mxmlc -define=CONFIG::DEBUGGING,false Main.mxml
            Loading configuration file /Library/Frameworks/Flex.framework/Versions/4.0.0.14159/frameworks/flex-config.xml
            Loading configuration file /Users/me/playground/flex/Main-config.xml
            /Users/me/playground/flex/Main.mxml(10):  Error: Access of undefined property HOSTNAME.
            
                 private var hostname:String = CONFIG::HOSTNAME;
            
            

             

            Still the same error. Is this not possible with mxmlc?

            • 3. Re: Problem overriding a conditional compilation definition
              Vikash.kumar29 Level 3

              Hi,

               

              Sorrry for the overlooking of value assigned in the CONFIG:HOSTNAME

               

              Try this, It works fine for me

               

              <flex-config>
                  <compiler>
                      <define append="true">
                          <name>CONFIG::HOSTNAME</name>
                          <value>"127.0.0.1"</value>
                      </define>
                      <define append="true">
                          <name>CONFIG::DEBUGGING</name>
                          <value>true</value>
                      </define>
                  </compiler>
              </flex-config>

               

              Hope, Now this solves your problem.

              Cheers

              -Vikash

              1 person found this helpful
              • 4. Re: Problem overriding a conditional compilation definition
                cheungpat Level 1

                Thanks for reminding to enclose strings in quote, but this doesn't solve the compilation problem for me.

                 

                I use this command to compile Main.mxml:

                 

                $ mxmlc -define=CONFIG::DEBUGGING,false Main.mxml

                And this is the output:

                 

                Loading configuration file /Library/Frameworks/Flex.framework/Versions/4.0.0.14159/frameworks/flex-config.xml
                Loading configuration file /Users/me/playground/flex/Main-config.xml
                /Users/me/playground/flex/Main.mxml(10):  Error: Access of undefined property HOSTNAME.
                
                     private var hostname:String = CONFIG::HOSTNAME;
                
                

                 

                No problem if I use this command to compile Main.mxml:

                 

                $ mxmlc Main.mxml
                

                 

                My Main-config.xml contents:

                 

                <flex-config>
                    <compiler>
                        <define append="true">
                            <name>CONFIG::HOSTNAME</name>
                            <value>"127.0.0.1"</value>
                        </define>
                        <define append="true">
                            <name>CONFIG::DEBUGGING</name>
                            <value>true</value>
                        </define>
                    </compiler>
                </flex-config>
                

                 

                Why is that?

                • 5. Re: Problem overriding a conditional compilation definition
                  theforwardway

                  mxmlc -load-config+=Main-config.xml -define+=CONFIG::DEBUGGING,false

                   

                  try "+=" in your compile arguments.