Monkeyshines now available for Flash

Monkeyshines now available for Flash

Jan 26

My physics/action game Monkeyshines has been available in the iTunes store Google Play for over a year now, but I decided to give it a refresher by porting so it could run with the Adobe Flash plugin. It was built with Unity and I could have easily published it using the Unity plugin, but I knew I could reach a far greater number of people if I opted for Flash (market penetration for Flash 11+ is 83% according to wikipedia).

Funny Flash Monkeyshines

Just want to see the end result? Play Monkeyshines in Flash

Besides being an opportunity to grow my audience for Monkeyshines, I was using it to check that all the features of my animation engine LeanTween were up to the challenges of running in a flash environment (I had heard people were still making flash games with it, but I hadn’t used that feature in awhile). So the first task was to upgrade all my actions to the latest LeanTween 2.0x, this took about an hour and was relatively painless.

Compile-time Errors in Publishing
After I got everything running with the new version of LeanTween I attempted to build the project. It’s worth pointing out that you get a lot of errors building that you do not get running the game within the editor (while Unity is pretty good at estimating the final product in the editor it is not a facsimile of the built product).

At first a lot of the build errors had to do with me including some iOS specific Social actions that Unity Flash does not support. By heavy use of compile dependent compilation switches, I was able to squelch those errors without having to remove the code, ex:

    #elif UNITY_FLASH

Social compile time errors made sense, but there were a number of errors that did not. To figure out these errors, I found it best to open up the compiled AS3 and see what line number in the compiled code was causing the error (the line number and file is mentioned in the error message). Don’t worry the AS3 code looks mostly like the C#/Unityscript that you programmed, so I think you will find it’s fairly easy to read. Most of the time, I would not really understand what specifically it didn’t like about my code, but I would just rewrite it in a different way, and voila: it would work. For example, in LeanTween I used to form a uniqueId like:

  int toId = _id | ((int)type << 24); // All in one-line The Flash compiler didn't like that, so I broke it into pieces like:

  int typeVal = (int)type;
  int toId = _id | typeVal << 24;

Another example, multidimensional arrays seem to break the flash compiler

  int bigArr[,] = new int[32,12];

So I converted it to a one-dimensional array:

  int bigArr[] = new int[32*12];

You may ask: Isn’t that more difficult to traverse? A little, but it’s pretty easy once you get the hang of it. Say you want to check a column along the 6th row of the fake multidimensional array you could do that like:

  int rowLength = 32;
  int rowPoint = 6;
  int maxSearch = rowPoint*rowLength + rowLength;
  for(int i = rowPoint*rowLength; i < maxSearch; i++){     Debug.Log("traversing row:"+bigArr[i]);   }

I felt pretty proud of myself after squashing each error, but every time I thought it was the last error, it would just move on to yet another error… Granted this would take a lot less effort, if I had built the game with Flash in mind from the beginning. I think it only took me about 1.5 hours to sort out all the compile-time errors (so not too bad).

Another tip, I would mention is that it seems to be best to avoid using generics like the Array class. I found it was best to use an Object[] array, or something similar like int[] (specifically typed array). Also speaking of generics, do not use Hashtables, you will have to find other ways to store your data like an Object[] array.

It works! Kind of…
Once I got all the compile times errors sorted out. I was amazed to see my game open up in a browser, and it looked like had worked… almost… it was deceiving to see how much of the game was working just fine… but there were some parts of the game that were not.

Flash Debug, and Vizzy
To solve the non-obvious problems, I had to turn to my trusty friend the Flash debug player on Firefox (Firefox is just easier to install since it doesn’t have it’s own version of the flash player like Google Chrome). Also Install Vizzy, so that you can easily see all of the Flash debug information.

One problem is that once my rigidbody engaged with anything, the game wold totally freak out. Unfortunately it was no-where in my own code, it was some raycast error caused by the Unity physics engine (sadly Unity is no longer supporting the Flash deployment officially, otherwise they may have worked to fix errors like this). To sort-out what was causing this, I slowly built my monkey rig back up from the simplest of pieces. During this process I found it was a character joint that was causing the error. Just by moving the anchor-point slightly off-center I was able to squelch this error.

That solved the major run-time error, but there were more to come. I trudged through most of the other runtime errors, by just printing out any information I could, and seeing where it was not matching my expectations. When in doubt about how to solve a malfunctioning piece of code, I suggest just rewriting those sections in a different way.

  For example, this worked:

  centeredStyle =; // new way

  But this did not:

  centeredStyle =“Label”); // old way

To close, although it was a big-pain to fix everything for this project, I think that mostly had to do with the fact that the code was sort of complicated and it was my first Unity project, so it was built in a way that was not following best practices. In the future I will look into porting my other Unity projects over to Flash, as it opens up so many more areas on the web that you can show off your project. So far I have ported it to:

    Facebook, demo with 7 levels

    Kongregate, Full-Game

    Google Chrome Appstore, demo with 7 levels, Full-Game

    Itch.IO, Full-Game

And I am trying to get it featured on a couple of other “Free Flash Games” websites, stay tuned for that…

If you know of any other websites out there I can host it on, please let me know!


  1. Rocki

    Excellent article.
    Super nice for sharing.

    You mentioned that it was your first Unity project and not following “Best Practices”. I’m curious what this means, could you elaborate a bit more. Is it “Best Practice” for exporting to Flash or in general. Come to think of it, a more detailed “Best Practice” guide for structuring a Unity Project for Flash would be very helpful in the future.


    • Thanks Rocki!

      Yeah I was thinking “Best Practices” in general. Of course this would be my interpretation of “Best Practices” but I could write an article detailing what I have adopted. Looks like I have to write another blog post 🙂

Leave a Reply