actionscript-3apache-flexcross-platformflex4.6

Compiling Flex Air apps for PC, Android and Mac from one codebase?


I would like to use Air to build for PC, Mac, Android, Ios.

Is it possible to do this from a single code base as Adobe Suggests.

Or will I need to maintain 4 separate builds?

Some guidance would be appreciated.


Solution

  • I have been able to maintain a single code base to date. I have done things like the following:

            private function getHostName() : void
            {
                if (NativeProcess.isSupported)
                {
                    var OS : String = Capabilities.os.toLocaleLowerCase();
                    var file : File;
    
                    if (OS.indexOf('win') > -1)
                    {
                        // Executable in windows
                        file = new File('C:\\Windows\\System32\\hostname.exe');
                    }
                    else if (OS.indexOf('mac') > -1 )
                    {
                        // Executable in mac
                    }
                    else if (OS.indexOf('linux'))
                    {
                        // Executable in linux
                    }
    
                    var nativeProcessStartupInfo : NativeProcessStartupInfo = new NativeProcessStartupInfo();
                    nativeProcessStartupInfo.executable = file;
    
                    var process : NativeProcess = new NativeProcess();
                    process.addEventListener(NativeProcessExitEvent.EXIT, onExitError);
                    process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutput);
                    process.start(nativeProcessStartupInfo);
                    process.closeInput();
                }
            }
    
            private function onOutput(event : ProgressEvent) : void
            {
                var strHelper : StringHelper = new StringHelper();
                formStationID.text = event.target.standardOutput.readUTFBytes(event.target.standardOutput.bytesAvailable);
                formStationID.text = strHelper.trimBack(formStationID.text, "\n");
                formStationID.text = strHelper.trimBack(formStationID.text, "\r");
            }
    
            private function onExitError(event : NativeProcessExitEvent) : void
            {
            }
    

    To take care of native calls. Other than the native calls I have found few things that can't be written generically, but of those, the above approach should work with any part of the code set as well.