Scripting

From FlashDevelop

Jump to: navigation, search

Contents

Description

The scripting in FlashDevelop is powerful way to extend the program or help you do specific tasks in your every day work. FlashDevelop uses the CSScript as a script engine which lets you run C# scripts inside FlashDevelop without compiling them with the C# compiler. The scripts are loaded in like plugins and therefore FlashDevelop might lock a temporary file which is the loaded module. When you close FlashDevelop the lock will be released.

Syntax and usage

Here is the command syntax that you can use for example with macros:

ExecuteScript|<ExecMode>;<ScriptFile>

Available execution modes are:

Runs the script in FD as a plugin and provides access to FD runtime instance. Locks the temporary file as it is loaded in to the same appdomain.

Runs the script and unloads it when finished without access to FD runtime instance. No file locking occurs as the temporary file will be released after execution.

Runs like "Internal" but changes the temporary file name so it locks a new temporary file everytime. Should be used only when developing new internal script.

Script syntax:

The scripts are simple. You need to have a public class of any name that contains a public static function called "Execute". This serves as an entry point for your script.

Documentation:

You can use the GitHub repository as your reference point when making new scripts. Also users of the community forums might be able to help you.

Samples

This simple sample opens the open file dialog of FlashDevelop.

Macro command:

ExecuteScript|Internal;C://Sample.cs

Sample C# script:

using FlashDevelop;

public class FDScript
{
    public static void Execute()
    {
        Globals.MainForm.Open(null, null);
    }
}

This sample adds custom menu items to FlashDevelop:

Macro command:

ExecuteScript|Internal;C://Sample.cs

Sample C# script:

using System;
using System.Drawing;
using System.Windows.Forms;
using FlashDevelop;
using PluginCore;

public class FDScript
{
	/**
	* Entry point of the script.
	*/
	public static void Execute()
	{
		// Get icon for menu items
		Image image = Globals.MainForm.FindImage("192");
		
		// Add a custom button to the toolstrip
		ToolStrip toolstrip = Globals.MainForm.ToolStrip;
		toolstrip.Items.Add(new ToolStripButton("Hello", image, OnHelloClick));
		
		// Add a menu item to the view menu
		ToolStripMenuItem viewMenu = Globals.MainForm.FindMenuItem("ViewMenu") as ToolStripMenuItem;
		viewMenu.DropDownItems.Add(new ToolStripMenuItem("Hello", image, OnHelloClick));
	}
	
	/**
	* Handles the click event for the menu items.
	*/
	public static void OnHelloClick(Object sender, EventArgs e)
	{
		MessageBox.Show("Hello");
	}
	
}

Share

As you can see scripting in FlashDevelop is easy and we hope that you'll share your scripts with other users in the community forums.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox