Xcode & Mtasc: Reloaded

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:

  1. Get the Actionscript Specification
  2. 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.
  3. 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.
  4. 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.
  5. 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!

4 Responses to “Xcode & Mtasc: Reloaded”


  • Hey Michael
    You’re obviously an expert on using Xcode with actionscript. I’m rather new to this and want to incorporate MTASC as suggested in your post.

    I have a quick question, is there a way for Xcode to automatically recognize changes to your project files at the finder level, ie when you drag new files to project folders in the finder or move files to different folders??

    Any help greatly appreciated!

  • Yes, but your source files need to me contained in a folder.
    Try doing this:
    1) In your current projects directory create a folder, call it ‘source’ or something, it will contain all your source files.
    2) drop the folder in Xcode’s ‘Groups & Files’ panel
    3) You should get a dialog asking you how you want to add the files. Make sure you select ‘Create Folder References For Any Added Files’
    4) The folder you just added should be showing the in the groups and files panel.
    5) Drop some folders/files in the newly added ‘source’ folder, then open & close the ‘source’ folder, the folder should update itself showing the newly added files.

  • Hi, you know if is possible adjust the size of the SWF Console? not manually, I mean automatically after the compilation with the original size of the swf. And another thing, is possible update the same window of SWF Console without close it to open the new swf?

    Thanks, I did try Eclipse for some days and I like more Xcode.

  • Sorry, I recompile the version 0.9.1 from the source and fix some code in the shell script and now all run perfect! Now I dont need to close the console window to refresh it with the last swf builded and I can resize it manually the first time.

    Thanks

Leave a Reply