Flash: Building & Running
The following is a step-by-step guide to build and run a new project exported to Flash.
- Create your Unity content.
- Choose File->Build Settings to bring up the Build Settings dialog and add your scene(s).
- Change the Platform to Flash Player
- Tick Development Build. (This causes Unity to not compress the final SWF file. Not compressing will make the build faster, and also, the SWF file will not have to be decompressed before being run in the Flash Player. Note that an empty scene built using the Development Build option will be around 16M in size, compared to around 2M compressed.)
- Press the Build button.
Unity will build a SWF file at the location you choose. Additionally an html and swfobject.js file will be created. To view your Flash-built content open the html file. (Do not open the SWF file directly).
As with other build target there are Player settings that you can specify. Most of the Flash settings are shared with other platforms. Note that the resolution for the content is taken from the Standalone player settings.
Build-and-run will create the SWF file, launch your default browser and load the generated html file. Note that there is a swfobject.js file created with handles the checking for the Flash Player and browser integration.
The build will also give you a swc file, which allows you to load the swf in your own project. Embedding the Unity content in a standard flash project allows you to do GUI in Flash. This type of flash integration will of course not work in any of the other build targets.
We allow for a Flash API that gives you texture handles, which in combination with the swc embedding will give you means to do webcam, video, vector graphics from flash as textures.
Texture Support
We support jpeg
textures, as well as RGBA / Truecolor. The compression ratio can be specified in the texture import under 'Override for FlashPlayer' setting. Compressed textures get converted to jpeg
with the chosen compression ratio. The compression ratio is worth experimenting with since it can considerably reduce the size of the final SWF.
Texture quality ranges from 0 to 100, with 100 indicating no compression, and 0 the highest amount of compression possible. The maximum supported texture resolution is 2048x2048.
Build Errors and Warnings
The Build Process
The Unity Flash Publisher attempts to convert scripts from UnityScript into ActionScript. In this process, there can be two kinds of conversion errors: errors during conversion of unity code to ActionScript, and errors while compiling the converted code.
Errors during conversion will point to the original will have the familiar UnityScript error messages with file names and line numbers. If there are errors in the ActionScript, the error will take you to the message in the generated ActionScript code (with filenames ending with .as
). It is possible that these ActionScript errors will not be easily understood. Just remember that the ActionScript is generated from your game script code, so any changes you need to make will be in your code and not the ActionScript.
Specific Errors and Warnings
1. What does this error message mean?
"Failed assemblies stripper ... Unhandled Exception: Mono.Linker.ResolutionException: Can not resolve reference: System.String UnityEngine.WWW::get_text()"
2. Why do I get:
'TerrainCollider' is not supported when building for FlashPlayer. 'TerrainData' is not supported when building for FlashPlayer. Asset: 'Assets/New Terrain.asset'
3a. Why do I get:
Error: Call to a possibly undefined method RuntimeServices_UnboxSingle_Object through a reference with static type Class.
- This is likely because the conversion between types that is defined on the UnityScript side is not defined for our Flash Publisher. Any time you see an error that refers to
Unbox
it means a type conversion is required but cannot be found.
3b. What should I do about this?
- Do not forget to use
#pragma strict
, and take care of all "implicit downcast" warning messages. - The rule of thumb is to avoid runtime casts from Object to primitive types (int, float, etc.). Also prefer containers with explicit types to generic ones, for example:
- System.Collections.Generic.List.<float> instead of Array
- Dictionary<string, float> instead of Hashtable
4. Why do I get
Error building Player: UnauthorizedAccessException: Access to the path "Temp/StagingArea/Data/ConvertedDotNetCode/global" is denied.
- If Unity-generated ActionScript files are open in a text editor, Unity may refuse to build issuing this error. To fix this, please close the ActionScript files and allow Unity to overwrite them.