11 Replies Latest reply on Oct 27, 2010 2:11 PM by JaumeMussons

    Conditional compilation ambiguity

    Lopo Nopo Level 1

      Hi,

       

      As usual the Flex docs lack non-obvious information.

      This time it's about conditional compilation.

       

      So, I've understood after a while that I should put

        "-define+=CONFIG::debugging,false"

      at the project's properties, under the "Flex Compiler" section, but now, because I see it doesn't make ANY sense to set debugging/release modes twice (false/true), I've searched for a better solution and found

        http://www.ubergeek.tv/article.php?pid=149

      which as you can see, writes this:

       

      <compiler>
          <define>
              <name>CONFIG::debugging</name>
              <value>true</value>
          </define>
          <define>
              <name>CONFIG::release</name>
              <value>!CONFIG::debugging</value>
          </define>
      </compiler>

       

       

      Now I understand it has to go to some file.

      BUT WHICH FILE ?!?!?!

       

      It's very frustrating that for each small thing needed to be accomplished at Flex we should go half a world..

      Can't the doc writers just mention these small details?? And you do understand that I'm not just talking about this one, right..

       

      So again, I've tried to put those "define" values at the file ".actionScriptProperties" under it's "compiler" section, makes most sense.

      Didn't work at all, even when simply setting "release" to false.

       

      So, any guru here that knows that?

       

      Thank you all and if any doc writer reads my feedback here - take it positively and learn from it - at bottom line you're ok

        • 2. Re: Conditional compilation ambiguity
          Lopo Nopo Level 1

          You must be kidding me.... Don't spam me with such messages.

           

          Does anyone here takes Flex seriously?

          .. Every question leads to three more..

          A simple 2-3 lines of answer is required, I'm sure.

           

          Where do I put this "flex-config.xml" file?

          How do I tell the compiler to look at it? I see someone there wrote "Use the -load-config argument of mxmlc to load it in". Where, again?!?

          • 3. Re: Conditional compilation ambiguity
            Michael Borbor Level 4

            That kind of configuration will be useful for you when you're using the mxmlc, or the flex command prompt compiler. If you're using Flex Builder, why would you need to do a conditional compiling? if you have a run mode, debug mode, and release build to play with?

             

            Flash Builder 4 has something called conditionals breakpoints, but I don't really get what you want to do. Keep it cool.

            • 4. Re: Conditional compilation ambiguity
              Lopo Nopo Level 1

              Hi,

               

              There's a simple reason for why I'm looking for such "conditional compilation";

               

              I have a huge application which when I debug it I really need to have some information... Lots of info, so I can't just "inspect" the data within Flex Builder's IDE. (By the way it's FB 3).

              Anyway to make the story short, I do not simply call "trace()". It's a more complex logging, and therefore there's a lot of code being executed at run-time, which I'd obviously would like to get rid of when I release the app.

               

              Being even more specific;

              On "Debug" release I'd log some text into a text box.

              On "Release" release I'd remove (or hide) that text box and I don't want any logging into it.

               

              At FB 3 I manage to put this on the project properties:

                "-define=CONFIG::debugging,true"

              But it's an incomplete solution...

              • 5. Re: Conditional compilation ambiguity
                Flex harUI Adobe Employee

                If my app is called Foo.mxml, then Foo-config.mxml contains the ... tags

                 

                 

                Alex Harui

                Flex SDK Developer

                Adobe Systems Inc.

                Blog: http://blogs.adobe.com/aharui

                • 6. Re: Conditional compilation ambiguity
                  Lopo Nopo Level 1

                  Ok, that's a progress

                  Find me the place where it's written!

                   

                  .. yet I hate to be dumb here but... consider the following:

                   

                  Have a project named "cond_comp", and it's main app file is named "cond_comp.mxml".

                  I've created a file named "cond_com-config.mxml" at the "src" folder, where the main app file resides.

                   

                  Now, the config file (by the way, are you sure it should end with "Mxml" ?) has this text in it:

                   

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

                   

                  <compiler>
                      <define>
                          <name>CONFIG::debugging</name>
                          <value>true</value>
                      </define>
                      <define>
                          <name>CONFIG::release</name>
                          <value>!CONFIG::debugging</value>
                      </define>
                  </compiler>

                   

                  And at the main app file "cond_comp.mxml" I have this code:

                   

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="370" height="256">
                      <mx:Script>
                          <![CDATA[
                              private function test():void
                              {
                                  CONFIG::debugging
                                  {
                                      trace("debugging mode");
                                  }
                              }
                          ]]>
                      </mx:Script>
                  </mx:Application>

                   

                  Yet I still get this compile error:

                  1120: Access of undefined property debugging.

                   

                  Can we get through it?

                  I'd loveeee it to work, a real addition to the Flash/Flex environment!

                  • 7. Re: Conditional compilation ambiguity
                    Flex harUI Adobe Employee

                    Sorry, it would be cond_com-config.xml

                     

                     

                    Alex Harui

                    Flex SDK Developer

                    Adobe Systems Inc.

                    Blog: http://blogs.adobe.com/aharui

                    • 8. Re: Conditional compilation ambiguity
                      Lopo Nopo Level 1

                      No problem of course, but are you sure that this works for you?

                      Because even though I renamed the file extension to ".xml" it remains with the same error.

                       

                      Should I "beg" a little more for the solution? Haha

                      • 9. Re: Conditional compilation ambiguity
                        Flex harUI Adobe Employee

                        I tried it with the code from your recent post.  I noticed two things:

                         

                        1)  The -config.xml file really needs to look this this (but you should have received a different error)

                         

                         

                        2) you misspelled the name of the -config.xml file in your post and if you actually did so, that would explain why you didn't get a different error.  If you have cond_comp.mxml, then the file must be named cond_comp-config.xml and not cond_com-config.xml

                         

                        Alex Harui

                        Flex SDK Developer

                        Adobe Systems Inc.

                        Blog: http://blogs.adobe.com/aharui

                        • 10. Re: Conditional compilation ambiguity
                          Lopo Nopo Level 1

                          All right!!

                           

                          Success.

                           

                          I did rename the file, you're correct.

                           

                          You see, you got "inside" information.. Where on the docs it's all written?

                           

                          Anyway to help others who might look for this I'll write the whole solution:

                           

                          cond_comp.mxml

                          <?xml version="1.0" encoding="utf-8"?>
                          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="370" height="256" applicationComplete="test()">
                              <mx:Script>
                                  <![CDATA[
                                      private function test():void
                                      {
                                          CONFIG::debugging
                                          {
                                              trace("debugging mode");
                                          }
                                         
                                          CONFIG::release
                                          {
                                              trace("release mode");
                                          }
                                      }
                                  ]]>
                              </mx:Script>
                          </mx:Application>

                           

                          cond_comp-config.xml

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

                           

                          <flex-config>
                          <compiler>
                              <define>
                                  <name>CONFIG::debugging</name>
                                  <value>true</value>
                              </define>
                              <define>
                                  <name>CONFIG::release</name>
                                  <value>!CONFIG::debugging</value>
                              </define>
                          </compiler>
                          </flex-config>

                           

                          Thank you Alex, VERY appriciated!

                          • 11. Re: Conditional compilation ambiguity
                            JaumeMussons Level 1

                            Hey, this is a great solution, but shouldn't it be extremely great if we could automate the whole process??

                             

                            I mean, tell the compiler to put a true when we are debuging and put a false when we execute a release build, so we do not need to change the "true" value to false every time we want to generate a release???

                             

                            Any idea?