ActionScript Manual     Reference     Scripting  
Scripting > Runtime Classes > ActionScript
ActionScript

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:

JavaScript
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 example : 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

class example(MonoBehaviour):

def Start():
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;
}
}
}

Class Functions
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.

Expression

Emits an ActionScript expression translating variable and field references to their ActionScript names.