Maintain 1 codebase for SWF that is sometimes standalone, sometimes module - actionscript-3

I have an app that has been a standalone app 'til now; however, in another app it's going to be a wee little module.
Is it possible to somehow maintain 1 codebase when the standalone has a source tag of:
<mx:Application>
and the module has a source tag of:
<myModuleBase>
Or is it better to keep a separate branch and just merge them together when the standalone has new changes that I want to propagate to the other?
The standalone app will eventually be taken down as part of phase 2 of this new project but that is several months off and features may be added in the interim.
Can I do this with a separate application file?
Thanks for any helpful tips!

This shouldn't be too difficult to implement. (Disclaimer: I have not messed with modules in Flex)
You have two top-level files, appNameStandalone.mxml and appNameModular.mxml
Those only include the main mx:Application and MyModuleBase tags, and contain inside them an MXML component that represents the actual application.
//appNameStandalone.mxml
<mx:Application ...properties>
<myComponents:UIAndFunctionalityComponent/>
</mx:Application>
//appNameModular.mxml
<MyModuleBase ...properties>
<myComponents:UIAndFunctionalityComponent/>
</mx:MyModuleBase>
If you're not certain how to do this in practice (say, in Flash Builder), you can work under one project directory with two Flex Applications (Project -> Properties -> Flex Applications) or have two separate projects containing only the top-level MXML file with the source folders containing the remainder of the application in the build path (Project -> Properties -> Flex Build Path -> Source Path).
If I've got some misunderstanding as to how the modular version works, please let me know and I'll attempt to correct my answer.

Related

PhpStorm: multiple projects with common core

Due to security reasons, I have to split one project to divisions (client, admin, ...), and deploy them to different web servers. These divisions have one common script base, but each division has its own functions. As an IDE I use PhpStorm.
The question: what is the best way to organize project's structure and settings, so the common core part will be visible for IDE indexing in all project's divisions, but at the same time, being maintained from a single project (perhaps, standalone)?
In Java you can do lib jar files for further linking in various projects.
But how it can be done in PHP?
There are multiple ways of how to reference extra PHP code in a project.
If you plan to actively edit such extra code in the same project (and want to see their TODOs, code inspection warnings, include references in code refactoring etc):
You can just add it as an additional Content Root: Settings/Preferences | Directories. Folder added this way will be treated as a part of the project itself and will be shown as a separate node in the Project View panel (just as the main code, which is a Content Root as well).
Or you can open 2nd project while 1st one is already opened and when asked, just chose "Attach":
It's not going to be full 2 projects in one frame, more like something in between attaching Content Root and having 2 projects opened in separate frames.
https://www.jetbrains.com/help/phpstorm/opening-multiple-projects.html
Simple symlink will also do the job (but you need to place it somewhere in a project, e.g. PROJECT_ROOT/libs/my_symlinked_code). You then will need to provide a path mapping for that folder for debugger (if you will debug it of course) as PHP/Xdebug works with "final/resolved path" while IDE works with the path as is.
If you do not need to actively edit that extra code in the same window (and ignore any TODOs, code inspection warnings and other inspection results etc):
Do it as a composer package then? Composer can use custom sources (e.g. GitHub repo or a folder on a local filesystem).
Just add the path to that folder as a "Include Path" at Settings/Preferences | Languages & Frameworks | PHP --> Include Path tab. Code referenced this way is meant for 3rd party libraries (the code that you just use but not edit, e.g. framework code, your send mail/ORM library etc). Composer packages will also be included here by default.
https://www.jetbrains.com/help/phpstorm/php.html#include-path-tab

Variable file include path in Flash Pro when build an android app using Air

As far as I know, the only way to include a folder in an Air package (in Flash Pro, not Builder) is through the GUI:
Publish Settings > Player Settings > General Tab > Included Files
... but it's kind of a huge hassle to manually add and remove folders over and over again if you have to publish the app with a dozen different versions of the content, you know?
Is there a way to conditionally include folders based on text somewhere - the app config xml, maybe? or something else that will be checked when the APK is compiled? That way I could just copy and paste in the folder name to switch which asset folder is being included, instead of going through the whole process inside of the flash IDE?
This idea might possibly be of some use although it could require some management due to possibly meaning you have duplicated assets.
I typically store all my assets inside an 'includes' folder/directory and just add this to the Settings > Include Files pane.
I also have folders which store the target specific includes, such as 'IOS' and 'ANDROID', (but aren't added to the Include Files pane).
When publishing, I swap out the contents of the includes folder. So it's just a case of deleting the existing contents if the includes folder and copy/pasting from the relevant source folder into the includes folder.
Hope that makes sense.
There are a couple of things you could do, though they're not 100% solutions per se.
1) Use conditional compilation:
Depending on how your imports/includes are set up, you could change it to always be the same file, but change the code/embed inside depending on a compile time constant. You can add a compile constant by going to File > Publish Paramaters > Flash (tab) > Parameters > Configure Constants:
Your constants would be in the form CONFIG::debug or FOO::bar, then in code, you wrap your code like this:
CONFIG::debug
{
// code is only included if CONFIG::debug is true at compile time
}
Then, by flipping constants, you can include or exclude blocks of code. There's a bit more detail here: http://divillysausages.com/blog/as3_conditional_compilation
NOTE: this is much easier to do in an IDE like FlashDevelop.
2) Use an external IDE
Taking the FlashDevelop example, when building for mobile, a number of .bat files are created. Depending on the environment vars set, you can include/exclude folders as you wish. I do this to include different assets depending on if it's a desktop, Android, or iOS build.
3) Use the Flex SDK command line or ANT
With either of these, you can specify a config.xml file for the files that you want to include. External IDEs (like FD) use the command line directly, so you can almost copy/paste the command if necessary.
For ANT, it's not my strongest point, but you can find out a bit more here: http://charlespatricknewman.com/blog/?p=325

Windows Phone 8 , how to share code,xmal,asset between multiple projects

Now I have AppA finished. but I want to make AppB,AppC. and AppB,AppC share most of the code in AppA(including xaml, asset, code,etc.). only a few changes for the AppB,AppC respectively.I mean, the 3 apps can be installed on the same windows phone separately with different icons.
Does anybody know how to build AppB,AppC referring AppA in code?
thanks.
Either extract as much as you can in a shared/common project or use "Add as Link" to include files from AppA into AppB and AppC.
Note that XAML files don't support conditional compilation so they must be identical for all projects in order to link them. You can potentially extract XAML differences into App.xaml StaticResources (identical keys) in order to make them identical and link them.
Sharing XAML is very reasonable when targeting the same platform.
You can also link cs files even if they are similar (few changes) by using conditional compilation.
Partial classes can also spare you the conditional compilation ceremony in many cases.
Finally Resource files are very good candidate for reuse. If you decide to put them on a shared library remember to wrap the generated Resource class in another public one with a public constructor shown here in order to avoid the internal constructor issue.
You can put all your code in an external class library. As far as I know though your assets and pages need to exist in each project.
If you want to share code and assets between multiple assemblies, you can create a class library for Windows Phone and put all the code inside it. When you need to use that library, simply link it in your target applications.
When you want to navigate to a page in your library, use the following syntax:
NavigationService.Navigate(new Uri("/AssemblyName;component/page.xaml", UriKind.Relative));

Sharing source between 2 projects?

I have a project containing a big package "global" of classes which is designed for Web, I need to share these classes with a new mobile project, but when i add them with :
Properties -> Flex Build Path -> Source path -> Add Folder
they start appearing with index [source path] before the package name, and since them Flash Builder start trowing error messages :
"A file found in a source-path must have the same package structure '', as the definition's package, 'global'."
How can i fix this issue ?
As we've discussed in the comments, I think it would be a better approach to compile your "global" classes into a library (.swc).
You were concerned about loading unnecessary classes: when you link to a library as 'merged', only the classes you use are actually compiled into the main application (and any classes they depend on), so there's no need to worry about that.
As a last argument I also think this is a more flexible approach. A compiled library is easier to reuse and version, so the code can more easily be distributed to other developers on your team.
Rename one of the packages with right click->refactor. Than is should work.
If not you can also try to have your two codes available at the same project, and then you can select which to run in Flash Builder, by right-clicking to that .as or .mxml file, and selecting set as ... (or something like that)
I guess if you will include 'src' fonder instead of 'src/global' that problem will disappear.

How can I divide unity configuration section into several files?

In my project there is some common package which gets its dependencies resolved by the UnityContainer which is defined in unity.config file.
There is another custom package which I want to have its own custom UnityContainer in a seperated CustomUnity.config file.
In runtime I want both files to be loaded and when I get the unity section, I want it to contain both UnityContainers.
How can i achieve it?
Thanks!
The UnityContainer.LoadConfiguration method can be called multiple times on the same container. Each time it loads whatever's in that configuration section, but it doesn't remove what was previously in the container - it's additive. If there's a conflict (both sections configure the same type) then last one in wins.
So, the approach would be to use the ConfigurationManager APIs to load your two separate UnityConfigurationSections, and then call LoadConfiguration twice, once for each configuration section. That should be all you have to do.
I wrote a library that lets you write your ioc container configuration in modules. It supports unity but you will have to configure your container in codes instead of using the files. I don't know if will solve your problem, but you can check it out at bootstrapper.codeplex.com