18 Replies Latest reply on Jun 23, 2010 7:17 AM by presx

    Config file?

    hidarikani Level 2

      Hardcoding HTTPService URLs is not a good idea if the app is going to be moved from server to server.

      Can Flex apps have config files of some sort?

        • 1. Re: Config file?
          injpix Level 3

          Have you looked into using a Resource bundle?  ResourceManager is a Singleton class that can retrieve values from a plain text file at run-time.  So you would only need to edit this plain text file to change URLs, and not recompile the application.

           

          About the ResourceManager
          Introduction to Flex Resource Bundles
          • 2. Re: Config file?
            hidarikani Level 2

            Isn't the ResourceManager for app localization?

            • 3. Re: Config file?
              Matt Le Fevre Level 4

              hidarikani wrote:

               

              Hardcoding HTTPService URLs is not a good idea if the app is going to be moved from server to server.

              Can Flex apps have config files of some sort?

               

              for one of our project, we develop it across three seperate servers, which is somewhat annoying!

               

              however, we did a quick and easy method so that the app can determine which server it is on.

               

              On application load, it sends off a PHP script which then returns server variables such as the following;

               

              http://roshanbh.com.np/2008/05/useful-server-variables-php.html

               

              which are then manipulated into the required format, and stored in variables in the flex app.

               

               

               

               

              However, theoretically you shouldn't need to do this. You should never be quoting full URLs in your flex application, or wanting to be.

               

              for example; you should always try to use:

               

              url="assets/php/script.php"

               

              rather than

               

              url="http://localhost/flexApp/assets/php/script.php"

               

              etc..

              • 4. Re: Config file?
                injpix Level 3

                Resource bundles are probably most useful, and most commonly used for, localization. Localization (pardon the didacticism) is the process of making software comprehensible for multiple regions with different languages or ways of writing. Sometimes you’ll see this term written L10n. For example, in porting your “Hello, world” application for a Japanese audience, you’d probably make it say something like “今日は、世界” instead. Resource bundles are perfect for supporting multiple locales.

                This obvious use case, I’m afraid, might have prevented many of you from looking into resource bundles. If resource bundles are for localization, and you’re building a site that doesn’t need to be localized, you might well overlook their benefits, as I did for some time.[my emphasis] However, here’s some of the benefits of using resource bundles — even if it’s just one single bundle.

                ref: http://dispatchevent.org/roger/introduction-to-flex-resource-bundles/

                • 5. Re: Config file?
                  oldMster Level 3

                  Using relative URL's is best, but we need to extract some of the URL for passing a parameter to our back end data service.  We also needed to know if it was running 'locally' during development, and had a default server that would provide the data services for the development work.  We did it like this:

                   

                  var baseurl:String = mx.core.Application.application.url;

                  var dataurl:String = "";

                  var pattern1:RegExp = new RegExp("http://[^/]*/");

                  var pattern2:RegExp = new RegExp("https://[^/]*/");

                  if (pattern1.test(baseurl) == true || pattern2.test(baseurl) == true) {

                       var urlarray:Array = baseurl.split("/");
                       this.ourparameter=urlarray[4].toString();
                       var location:String =urlarray[3].toString;
                       location=location.toUpperCase();
                       this.ourparameter=this.ourparameter.toUpperCase();
                       dataurl="https://" + urlarray[2].toString() + "/scripts/some.dll?ourparameter=" + this.ourparameter;
                  }else {
                  }
                  Mark

                  • 6. Re: Config file?
                    Sebastien V. Level 3

                    The mx.utils.URLUtil supplies some pretty usefull methods to deal with urls, it could save you from RegEx and String parsing, depending on what you need to do with the application's URL.

                    • 7. Re: Config file?
                      oldMster Level 3

                      Thanks, I hadn't found that class yet.  Would have saved some work, but still would have to do the string parsing to extract the items we need.  String parsing is a natural activity for me, our back end database is all about strings.

                      Mark

                      • 8. Re: Config file?
                        presx

                        Hello oldMster, this really work? I give some compiled vb6 dll, create a request from this and have a good communication between this and my As3 application?

                         

                         

                        I'm gratefull for your attetion by now. Sorry for my bad english.

                        • 9. Re: Config file?
                          oldMster Level 3

                          presx,

                          My examples didn't have anything to do with generating the URL with VB6, it was all actionscript that was determining the correct URL and POST parameters to use for HTTP requests based on the URL of the HTML file that launched the SWF.

                           

                          If you plan to generate HTTP requests to servers other than the server the SWF was launched from, be sure you understand cross-domain.xml setup and useage.

                           

                          Mark

                          • 10. Re: Config file?
                            presx Level 1

                            I have to said any wrong in my question. I look for any weeks around realize calls to an DLL archive with many directions. But, i don't have success. I try to do this with the MDM Zinc, but also failed with this try.

                             

                            I have look in many places around an solution to solve this communication. The only happy way i find to solve this, is practically rewrite the DLL functions on C# Services and using FluorineFx when i use this published on the IIS and access these functions.

                             

                            I look for a simplest way where a As3 have directly access to my DLL and try a conversation with this. When i look your post i remembering a little instant insight i have in the final of last week, when i have abandoned this idea of DLL access and work in others parts of the project.

                             

                            Anyway, thank for your attention. And sorry for my english again

                            • 11. Re: Config file?
                              oldMster Level 3

                              Presx,

                              If what you were trying to do was call a DLL directly, that is not supported from a Flex/Flash application running in a browser.  However, AIR 2.0, which was just released today, does allow you to call native processes directly from the environment.  If you aren't familiar, AIR allows you to package a Flex/Flash application to be installed and run as a local application, rather than in a browser.

                              Mark

                              • 12. Re: Config file?
                                presx Level 1

                                Hello Mark, i'm very gratefully for your attention. Very thanks! I have downloaded the new AIR SDK version and try to test any things around this in few hours. Lately i repass my experience around this. I'm a flash designer / dev, and have short contact with flex in fell tree months. It's a great pleasure for me wok'in with this.

                                 

                                See ya in the sequence of facts ;D

                                 

                                P.S.Sorry for my bad english!

                                • 13. Re: Config file?
                                  presx Level 1

                                  Mannnn, i'm very frustrated... soo tired around config de new packages updates and try compile versions, and update run time... u know about i talk, i think. I try to compile anything can get a return of tha NativeProcess class, but this not compile fine. The app window dont launched, and my App project freeze Oo. U belive this?

                                   

                                  Ahhhh, don't late to talk about the update in the sdk, i copy the sdk.3.5 and merge with the package air_rc_win, download from a link in the adobe's labs.

                                   

                                  When i compile only with tha mxml application default:
                                  <?xml version="1.0" encoding="utf-8"?>
                                  <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                                      <mx:Script>
                                          <![CDATA[
                                             
                                              import mx.controls.Alert;
                                             
                                              public function init():void
                                              {
                                                  Alert.show('borwa');
                                              }
                                             
                                          ]]>
                                      </mx:Script>
                                  </mx:WindowedApplication>  <= this works, fine.

                                   

                                  But when i put something like:

                                   

                                  <?xml version="1.0" encoding="utf-8"?>
                                  <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"  layout="absolute" creationComplete="init()">
                                      <mx:Script>
                                          <![CDATA[
                                             
                                            import mx.controls.Alert;
                                            import flash.desktop.NativeApplication;

                                   

                                            public var mProcess:NativeProcess;

                                   

                                            public function init():void

                                            {

                                              Alert.show('mNative => ' + mProcess);

                                             }

                                          ]]>

                                  </mx:Script>

                                  </mx:WindowedApplication>  <= this freeze the publication process of the flex builder 3 ide. And only by exclusion of the project and creation of a new this come to work fine any more time.

                                   

                                  Is this... is this... i try any more times, I will find the way to do this work. Thanks one more time.

                                  • 14. Re: Config file?
                                    oldMster Level 3

                                    To use the NativeProcess, you need to have <supportedProfiles>extendedDesktop desktop</supportedProfiles> in the application.xml (application is whatever your project name is).

                                    Mark

                                    • 15. Re: Config file?
                                      presx Level 1

                                      Hello Mark, are u fine? Really i forget this detail, but i fix this and the xml namespaces too, how i forget this man, so my mind is trashed i think. I fix all these details but nevertheless my example don't work.

                                       

                                      When i change the xmlns to xmlns="http://ns.adobe.com/air/application/2.0beta" or xmlns="http://ns.adobe.com/air/application/2.0beta2" this don't launch a compilation window. When i back the value in my "application.xml" to xmlns="http://ns.adobe.com/air/application/1.5.3" this return to build normaly.

                                       

                                      Well, i continuing try this to work.

                                       

                                      Thank's for attention. ;D

                                      • 16. Re: Config file?
                                        oldMster Level 3

                                        Ok, there is a problem.  For the release candidate SDK, the namespace should be "http://ns.adobe.com/air/application/2.0"

                                        Mark

                                        • 17. Re: Config file?
                                          presx Level 1

                                          Hello Mark, are you fine? I found time again to back to this project and have a little happy when i compile with the new xmlns for the 2.0 SDK. The example is running. Anything is wrong, i can't find the classes of NativeProcess, NativeProcessStartupInfo needed to work with NativeProcesses.

                                           

                                          When i use the alert pops with the runtimeVersion command that return me the version 2.0.2.12610. I'm look for my errors on process to create the "package version"  of the AIR 2.0 Sdk to try more times. I think this doing wrong work in my enviroment.

                                           

                                          I continue to find the way to access these features of the new Air Sdk, but i revealing acquiring a failure sensation with these experiences.

                                           

                                          Very thanks! And sorry for my stupid english and see ya later! Hugs!

                                          • 18. Re: Config file?
                                            presx Level 1

                                            I´ve finally done the compilation work's with NativeProcess classes =D

                                             

                                            As i suspected, i'll forgot to configure the actionScriptProperties of the project, with this ok i will to the next step, make call some dll functions to test this new AIR features.

                                             

                                            I will post news later. Very thanks for your attention!