6 Replies Latest reply on Jul 19, 2010 7:21 AM by aabarreiros

    Problems with include's

    aabarreiros

      Hi all,

      My actually project it will be exported in flex and air, but i need to incluede diferent .as files for the diferent projects, is there anyway for me to make the includes dynamically?? for instece

       

      if(air){

      include "desktop/myfile1.as"

      include "desktop/myfile2.as"

      include "desktop/myfile3.as"

      }else{

      include "online/myfile1.as"

      include "online/myfile2.as"

      include "online/myfile3.as"

      }

       

      Thanks in advance

      Alex

        • 1. Re: Problems with include's
          BhaskerChari Level 4

          Hi aabarreiros,

           

          yes it is possible to include the as files dyncamically based on the condition..

           

          Always path to the include directive should be a relative path.

           

          Try referring to the below link you will find more information:

           

          http://www.adobe.com/livedocs/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Li veDocs_Parts&file=00000456.html

           

           

           

          Thanks,

          Bhasker  Chari

          1 person found this helpful
          • 2. Re: Problems with include's
            aabarreiros Level 1

            Hi BhaskerChari,

             

            But my problem is for instance i have the same function name in myfile1.as when i do

            <mx:Script>
                    <![CDATA[
                        if(air){
                           include "desktop/myfile1.as"       
                        }else{
                            include "online/myfile1.as";
                         
                        }
                    ]]>
                </mx:Script>

             

            i get double function name error, for me it's imperative to have the same function's name for the code be exactly the same for my air/flex app

             

            Thanks again

            Alex

            • 3. Re: Problems with include's
              BhaskerChari Level 4

              Hi Alex,

               

              i dint get you correctly when you are including the as files conditionally how there is a posssibility to have double functions included when there is only one as file being included.

               

              Thanks,

              Bhasker

              • 4. Re: Problems with include's
                aabarreiros Level 1

                Hi Bhasker,

                My MXML is something like this:

                <?xml version="1.0" encoding="utf-8"?>
                <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                    <mx:Script>
                        <![CDATA[
                            private var _air:Boolean = true;
                        ]]>
                    </mx:Script>
                    <mx:Script>
                        <![CDATA[           
                            if(_air){
                                include 'files/desktop/myFile.as';
                            }else{
                                include 'files/online/myFile.as';
                            }           
                        ]]>
                    </mx:Script>
                    <mx:Button label="Click" click="showMessageAlert()"/>
                </mx:WindowedApplication>

                 

                Than i have 2 files

                this is the desktop include

                // ActionScript file
                import mx.controls.Alert;

                 

                public function showMessageAlert():void{
                    Alert.show("desktop","desktop include");
                }

                 

                and this the online include

                // ActionScript file
                import mx.controls.Alert;

                 

                public function showMessageAlert():void{
                     Alert.show("online","onlineinclude");
                }

                 

                If i run the sample i get the error double function definition, i'm i doing something wrong??

                 

                Thanks

                Alex

                • 5. Re: Problems with include's
                  UbuntuPenguin Level 4

                  Generally I would think of conditional includes as questionable practice ( in Flex at least ) unless there was absolutely no other option.

                   

                  Message was edited by: UbuntuPenguin

                  • 6. Re: Problems with include's
                    aabarreiros Level 1

                    Hi there UbuntoPenquin,

                    For my problem i don't find any other option if i want to have in the same project the flex&air if i get this to work the only thing i have to change in my project to export air or flex is a variable that indicates me if it's an air or flex project and the <mx:application or <mx:WindowedApplication ta, the project will be exactlly the same and i don't need to have 2 projects for the same propose

                     

                    Best regards

                    Alex