Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

ActionScript

Namespace: UnityEngine.Flash

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Inline ActionScript support.

When targetting the Flash Player, it is often convenient to be able to execute some manually written ActionScript. Examples of this would be: talking to some flash API (think networking, sockets), running some existing ActionScript code, or integrating with some 3rd party ActionScript library. You can call "handwritten" ActionScript methods, and get return values from them most easily like this:

	import UnityEngine.Flash;
	
	function Start()
	{
		ActionScript.Import("com.mycompany.mytool");
		var name = "Lerpz";
		var protocolversion = ActionScript.Expression.<int>("com.mycompany.mytool.GetProtocolVersionFromServer({0})", name);
	}
using UnityEngine.Flash;
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Start() {
        ActionScript.Import("com.mycompany.mytool");
        string name = "Lerpz";
        int protocolversion = ActionScript.Expression<int>("com.mycompany.mytool.GetProtocolVersionFromServer({0})", name);
    }
}
import UnityEngine.Flash
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Start() as void:
		ActionScript.Import('com.mycompany.mytool')
		name as string = 'Lerpz'
		protocolversion as int = ActionScript.Expression[of int]('com.mycompany.mytool.GetProtocolVersionFromServer({0})', name)

You then also have to provide the ActionScript file that contains the com.mycompany.mytool actionscript class. You can do this by creating a folder called "ActionScript" anywhere in your Project Folder, and adding the ActionScript class file in there, respecting ActionScripts requirements that the path needs to match the class namespace. In this example, you would place this ActionScript file:

	package com.mycompany 
	{
		public final class mytool
		{
			public static function GetProtocolVersionFromServer(name: String): int
			{
				//talk the the flash api here.
				return 18;
			}
		}
	}

Static Functions

Expression Emits an ActionScript expression translating variable and field references to their ActionScript names.
Import Causes an import directive to be emitted in the ActionScript code generated for the current type.
Statement Emits a block of ActionScript code in the current method translating variable and field references to their ActionScript names.