10 Replies Latest reply on May 2, 2009 8:02 AM by Barna Biro

    How to access code in other projects?

    ehwhoknows

      Hi all,

       

      I ran into an issue in FlexBuilder I'm not sure how to resolve, hopefully someone here can help.  I have several projects in my workspace right now I'll call them project A and B.  I have one project in particular, call that project C, that needs access to code contained in a couple of other projects, A and B.  I don't want to copy all those files from the other projects into this one cause there's a lot of files, it's tedious, and unmaintainable.  I don't want to make all those files into a flex library either cause it's not really necessary.

       

      I tried adding the folders in project A and B into the source path of project C but when I tried to import those files it did not work.  So does anyone know of a way that I can access code from other projects in the same workspace?  If you could provide an example also that would be greatly appreciated.

       

      Thanks in advance.

       

      Additional info: The code complete for the import actually shows me the files in the source path are available.  In fact, when I hit F3 it points me to the proper file in the other project.  However, FlexBuilder keeps telling me the type was not found or it isn't a compile time constant.

        • 1. Re: How to access code in other projects?
          ntsiii Level 3

          In Project, Properties, BuildPath, Library path, there is an "add Project" button.  I have not used that but it sounds like it might help you.

           

          Tracy

          • 2. Re: How to access code in other projects?
            Barna Biro Level 3

            Hi there,

             

            ntsiii's method would be a solution but I'd like to suggest something ( for future projects ): learn OOP and try to put everything in classes that can be reused. You can create a Library project that would server as a huge "bagage" of classes that you can reuse from application to application. Accessing code from project A in project B is totally not cool and you'll be only messing up things really badly ( what happens if you need to change something in project A? Then project B would be totally messed up. ).

             

            Definitely learn OOP and start writing classes that can be reused easily, that's the right way.

             

            With best regards,

            Barna Biro

            • 3. Re: How to access code in other projects?
              Michael Borbor Level 4

              Barna let me disagree with you, while OOP is a good design pattern and AS3, is object oriented, that doesn't mean that is has to be rule for every single project and that it has to be to way to go always, I believe a few airlines still use software that was written in the 80's and that software I guess that wasn't written using OOP and  that has scale well too, so OOP isn't the holy grial.

              • 4. Re: How to access code in other projects?
                Barna Biro Level 3

                Exceptions always exist but if you don't see the benefits OOP and design patterns can bring then we are definitelly "not on the same team". Obviously, you won't be using OOP or whatever to simply test something or for a simple contact form written in Flex, but if you are working on "a real project" then I don't see what's wrong in "plan for the future". By that I mean: "structure your code in a way that you can reuse more important elements in other projects if needed" or even write your own library that can be reused in almost every project.

                 

                Not using OOP and design patterns when developing stuff in ActionScript 3.0 is like saying "don't use separate classes in Java, simply write everything into a single file" and that's totally not called programming ( no matter how you look at it ). You can't get better by ignoring the stuff that is around you and the benefits it can bring ( even if it's a really small project; you might never know when will a certain piece come in handy ).

                 

                Anyway, this is just my personal opinion. Experience thought me to "always plan for the future", even if a certain solution might seem a bit of an overkill for a certain project, it does not mean that stuff I wrote there will never come in handy for a different project. But if I don't write my stuff correctly then I would find myself wasting precious minutes/hours trying to reproduce something that I might have even forgotten how to build and adapt instead of simply having a "drag and drop" class that was built with "reusability in mind".

                 

                If you feel that simply writing code without ever thinking with 2-3 seps ahead then all I can say is "good luck". I'm sticking to the stuff that proved to be of great use for me and my projects on the long run. As I said, this does not mean that one should abuse of OOP, you would obviously not waste time thinking how to structure your stuff if you simply want to test something or if you're building a contact form ( athough, the validation part could be separated there too or even other parts and reused in future contact forms ) but even if you do, you'll still be ending up with better results on the long run than taking the "write everything into a file and just get it work".

                 

                With best regards,

                Barna Biro

                • 5. Re: How to access code in other projects?
                  Muzak Level 3

                  If you have classes that you want to reuse across several projects but don't necessarily want to make them into a Library, you can move those files to a separate folder (preferably outside the FB workspace) and include that directory in any project that requires it. I use that all the time.

                   

                  I have my Flex workspace located at: "E:\Flex 3" and have a class repository in "E:\FlexClasses".

                  If a project requires classes from the repository, include its path in the project source path:

                   

                  Project Properties -> Flex Build Path -> Add Folder

                  Browse to the directory your classes are in (in my case that's "E:\FlexClasses") and you're done.

                   

                  Additionally you can create a "Linked Resource" that points to the class repository and use that instead (that's what FB does to point to the FB install dir).

                  To do so, in FlexBuilder, go Windows -> Preferences.

                  Select General -> Workspaced -> Linked Resources and click "New".

                  Fill in a name for the Linked Resource (e.g. FlexClasses) and browse to the folder that contains your classes (e.g. E:\FlexClasses).

                   

                  Once you have a Linked Resource you can use it to refer to the directory it points to like this: ${FlexClasses}

                  where "FlexClasses" is the name of the Linked Resource. So instead of adding "E:\FlexClasses" to the Flex Build Path by browsing to that directory, you'd just write ${FlexClasses}.

                   

                  See attached screenshots.

                  • 6. Re: How to access code in other projects?
                    Michael Borbor Level 4

                    I never said don't use OOP, Flex SDK is all about classes, and abstraction, but last time I check there wasn't polimorphism, so AS3 it's not yet a purely OO. Instead of learning this architectural stuff If I were new to Flex, first I'll learn what the heck is the Flex SDK, and obviously AS3, then I can move on to design patter, singletons, decorators, PureMVC, and so on.

                    • 7. Re: How to access code in other projects?
                      ATIF FAROOQ Level 3

                      yes Michael i aggree with you there is no method overloading and operators overloading like in java. I hope these deficiencies will also be eliminiated by Adobe in next Version of flash Player and Actions Script

                      • 8. Re: How to access code in other projects?
                        Barna Biro Level 3

                        Michael Borbor wrote:

                         

                        I never said don't use OOP, Flex SDK is all about classes, and abstraction, but last time I check there wasn't polimorphism, so AS3 it's not yet a purely OO.

                         

                        No polymorphism? You should check again. Just because overloading is not supported that does not mean that polymorphism can't be applied. Polymorphism does not start or end with overloading, please read up on polymorphism ( http://www.adobe.com/devnet/actionscript/articles/oop_as3_05.html or find a more generic definition and see that polymorphic principles can be applied in AS 3.0 too ).

                         

                        No, ActionScript is not purely OOP, but what is? The only language I know of that is considered "a pure OOP language" is Java. Does that make other languages less good? Definitely not. Just because AS 3.0 does not support overloading it does not mean that OOP principles can't be applied and nor does it mean that it's not a valid OOP language.

                         

                        Michael Borbor wrote:

                         

                        Instead of learning this architectural stuff If I were new to Flex, first I'll learn what the heck is the Flex SDK, and obviously AS3, then I can move on to design patter, singletons, decorators, PureMVC, and so on.

                         

                        Well, sice I don't know ehwhoknows and I have no idea how new he is ( he may be new to Flex but that doesn't mean that he is new to programming ), I took "the risk" to add an additional opinion to his post saying that "sure what ntsiii said is totally cool but in the future, you might want to read up on OOP and design patterns because they offer much more than mixing projects in a barbaric manner".

                         

                        Obviously, if he is new to programming ( a detail that I don't see being mentioned in his post ) then he should stick to the simple things, but does that mean that we can't point out other solutions that may be more complex and harder to understand for a newbie at the moment. At least, he'll now know that there are other solutions out there too. Everything has it's time, but without telling him that "hey, solution A si ok, but solution B would be much better on the long run" then how do you expect him to find out about solution B? By accident?

                         

                        I wasn't trying to prove anyone wrong, all that I wanted to point out is that there are other solutions out there too that offer much more on the long run. If he can't handle OOP at the moment, no problem, but at least give him the chance to try it out.

                         

                        @ ATIF FAROOQ: I totally agree that it would be nice if the guys at Adobe would implement overloading and not only, abstract classes would be nice too ( and I mean "real abstract classes" like in Java, not workarounds ).

                         

                        @ Muzak: Totally agree, I said to use a Library mainly because that's what I use most ( beside simply pasting classes from a project into another; I do this occasionally and sometimes when I'm lazy ). In either case, the final goal is achieved: reusability.

                         

                        With best regards,

                        Barna Biro

                        • 9. Re: How to access code in other projects?
                          Michael Borbor Level 4

                          Yes but that characteristic isn't fully implemented that was I meant, 

                          I love AS3 if not what the heck I'm doing here. Man you would lose it 

                          in a MS meeting those guys enjoy saying bad stuff about AS3 just for 

                          fun.

                           

                          All I mean is that is small projects using OOP adds an overhead to the 

                          project completion, you could go as well in a procedural way grouping 

                          related functions and the result will be the same, but if you're 

                          working in a big project or with a group of developers OOP and design 

                          patterns will be the way to go, period.

                           

                          Sincerely,

                           

                          Michael

                           

                          El 02/05/2009, a las 8:41, Barna Biro <forums@adobe.com> escribió:

                          • 10. Re: How to access code in other projects?
                            Barna Biro Level 3

                            Good to know that we finally agreed on something.

                             

                            With best regards,

                            Barna Biro

                             

                            PS: The guys at MS aren't so bad, they do what they do only as a show.