I’ve devised a much better way of developing Flash with Xcode then what i previously posted. It uses the custom ‘Shell Script’ build phase in Xcode to call the Mtasc compiler. There are a number of advantages of this method over the applescript->Xmtasc->Flash Player route that was posted earlier:
- If their is an error in your AS code mtasc will exit with a non-zero status, the shell script will exit with an error if mtasc exits with an error. This is really cool because when the shell script exits with an error the ‘Build Results’ window comes up and shows the output from Mtasc, if you double click on the error it will bring you right to line of the file where the error is; just like when you’re coding Objective-C or any other language that Xcode natively supports.
- You can open up the compiled SWF with any SWF player of your desire.
- You can easily switch between which SWF you currently want to compile by using the target’s pop-up menu in Xcode.
- The standard ‘Build’ button now works! This means that cmd+b will build your project, unfortunarly the ‘Build & Run’ button wont work, it will build the swf but will give you an error when Xcode tries to open it up.
To put this whole system together is fairly simple, you could just download a already made sample project with the shell script build phase already put in place, or follow the following directions:
- Get the Actionscript Specification
- Create a new empty Xcode project. In Xcode go to File->New Project and select ‘Empty Project’. Create a basic project structure that is generic to all your Flash projects, just as directed on the diretions from Pixel Consumtion.
- Go to ‘Targets’ item on the left side of Xcode. Right click on it, from the contextual menu choose Add->New Target, then from the target window choose ‘Shell Script Target’. Name it whatever you please.
- Once the new shell script target has appeared in your ‘Targets’ menu, click the little arrow on the newly created target, you should now see an item named ‘Run Script’. Click on it then press cmd+i. Under the ‘Script’ section paste this script:
#simple compile and view script for MTASC #global vars, swf = the target swfs name, swfplayer = the name of the swfplayer swf="./main.swf" swfplayer="SAFlashPlayer" mtasc=/Applications/mtasc/mtasc #compile the swf $mtasc classa.as classb.as /class/ina/dir.as -cp "/A Class Path" -cp /Applications/mtasc/std -swf $swf #check for errors if [ $? != 0 ] then exit 1 else open -a $swfplayer $swf exit 0 fi
There are three variables that are important in this script:
- swf. The $swf variable is the path to the swf you are going to be compiling.
- swfplayer. The name of the application that you want to play your swf.
- mtasc. The path to your Mtasc binary.
- Save the project, close it, then copy it to:
/Library/Application Support/Apple/Developer Tools/Project Templates/Flash/
Your project should come up in the options for File->New Project (you might need to restart Xcode- not sure). You should be able to define the global variables and build your swf. To add the ability to compile different swfs just duplicate the original target and define the variables in the swf. You could even add a custom phase to script for building a Swfmill library. Although this system works fairly well, there is still no debugging without traveling back to the Flash IDE, which is a very big problem. Fortunatly there are a few options:
- Ricci Adams has created a great Open-Source app, Swf Console which works great and provides a nice GUI for Swf Dump, Flasm, and Flare.
- The almighty Admin Tool.
- A simple Debug Class I made.
Those are the main choices I am aware of. I personally use my debug class since its very light weight and is built into the swf. Just simply call debug.trace(“something”+var); to trace ouput.
Hopefully you’ve found some of this info usefull!