ScriptField |
A multi-line text field with optional syntax highlighting for scripts written in the ActionScript 3/haxe, xml/flex/degrafa/svg/xaml or ruby/hotruby. Lua and io languages are commented out. It uses a vertical scrollbar and word wrap to display scripts that are larger than the viewable area.
The performance of the current syntax highlighting implementation limits it to be usable by smaller scripts and code snippets. Syntax highlighting can be turned off when displaying larger scripts.
ScriptField | A multi-line text field with optional syntax highlighting for scripts written in the ActionScript 3/haxe, xml/flex/degrafa/svg/xaml or ruby/hotruby. |
Public constants | |
DEFAULT_WIDTH | Default width of a script window. |
DEFAULT_HEIGHT | Default height of a script window. |
defaultColor | Default base theme color of text and scrollbar in a script window. |
defaultFontSize | Default size of the text font used in a script window. |
Private display objects | |
input | Internal text field used for display and edit of scripts. |
scrollbar | Vertical scrollbar to allow browsing of larger scripts. |
Private callback functions | |
changeCallback | Optional callback triggered when the text in the scriptField has been changed. |
keyDownCallback | Optional callback triggered when a keyboard button is pressed down while focus is in the scriptField. |
Private data members | |
scriptEngineName | Name of the script engine language currently used for syntax highlighting. |
syntax | A dynamic object holding syntax properties of the current script language. |
Public property | |
enableSyntaxHighlight | Property indicating if syntax highlighting is on or off. |
Constructor | |
ScriptField | Creates a multi-line script field with word wrap and a vertical scrollbar. |
Public properties | |
text | Retrieve the current script text. |
text | Change the script text displayed in the field. |
changeHandler | Change the callback function called when the script is changed. |
keyDownHandler | Change the callback function called when a keyboard button is pressed. |
Public methods | |
home | Displays the top of the script that is the home position. |
Script hightligthing | |
language | Sets the scripting language for the text field. |
syntaxHighlight | Syntax highlights by setting text formats on the script field text. |
Event handlers | |
inputChangeHandler | The text in the input field has been changed |
inputKeyDownHandler | A keyboard key has been pressed in the input field. |
scrollHandler | The user has scrolled the text in the input field. |
scrollbarHandler | The user has manipulated the scrollbar position. |
WidgetInterface | |
active | Sets the state of the widget to active or inactive. |
activate | Activates the widget, adds its event listeners |
disactivate | Disactivates the widget, removes its event listeners |
dispose | Dispose of all resources used or referenced in the instance. |
destructor | Removes used resources, references and graphics |
private var syntax: Object
A dynamic object holding syntax properties of the current script language. The properties are strings with regular expressions for matching lexical tokens.
multiLineCommentBegin | begin of a comment block; for lua “--[[“ |
multiLineCommentEnd | end of a comment block; for lua “]]” |
singleLineComment | comment to end of line; for lua “--” |
keywords | words that are highlighted as keywords; for lua “and|break|...” |
operators | tokens that are highlighted as operators; for lua “+|-|*|/|...” |
hexPrefix | prefix used for hex numbers; for lua null, for as3 “0x” |
public function ScriptField( owner: String, inputText: String = "", fieldWidth: uint = DEFAULT_WIDTH, fieldHeight: uint = DEFAULT_HEIGHT, color: uint = defaultColor, fontSize: uint = defaultFontSize )
Creates a multi-line script field with word wrap and a vertical scrollbar. No script language is selected.
owner | name of registered owner; see WidgetSprite.register |
inputText | initial script text displayed in the field |
fieldWidth | width of the field (default 200 pixels) |
fieldHeight | height of the field (default 200 pixels) |
color | base theme color for the script text and scrollbar (default MediumGrey) |
fontSize | size of the font used (default 10) |
public function set changeHandler( changeHandlerFunction: Function ):void
Change the callback function called when the script is changed. Set to null to disable callbacks.
changeHandlerFunction | function called when the script text changes |
changeHandlerFunction | function onScriptFieldChange(script:String):void |
public function set keyDownHandler( keyDownHandlerFunction: Function ):void
Change the callback function called when a keyboard button is pressed. Set to null to disable callbacks.
changeHandlerFunction | function called when a button is pressed |
changeHandlerFunction | function onScriptFieldKeyDown(event:KeyboardEvent):void |
public function set language( scriptLanguageName: String ):void
Sets the scripting language for the text field. For syntax highlighting to be displayed the enableSyntaxHighlight property must be set to true.
The implementation could be changed to retrieve the language details from an external source (XML file or Soap server) to avoid code bloat if the number of languages increases.
scriptLanguageName | Either “as3”, “haxe”, “xml”, “degrafa”, “svg”, “xaml”, “ruby”, “hotruby” or “” to disable |
Default width of a script window.
public static const DEFAULT_WIDTH: uint
Default height of a script window.
public static const DEFAULT_HEIGHT: uint
Default base theme color of text and scrollbar in a script window.
public static const defaultColor: int
Default size of the text font used in a script window.
public static const defaultFontSize: int
Internal text field used for display and edit of scripts.
private var input: TextField
Vertical scrollbar to allow browsing of larger scripts.
private var scrollbar: Scrollbar
Optional callback triggered when the text in the scriptField has been changed.
private var changeCallback: Function
Optional callback triggered when a keyboard button is pressed down while focus is in the scriptField.
private var keyDownCallback: Function
Name of the script engine language currently used for syntax highlighting.
private var scriptEngineName: String
A dynamic object holding syntax properties of the current script language.
private var syntax: Object
Property indicating if syntax highlighting is on or off.
public var enableSyntaxHighlight: Boolean
Creates a multi-line script field with word wrap and a vertical scrollbar.
public function ScriptField( owner: String, inputText: String = "", fieldWidth: uint = DEFAULT_WIDTH, fieldHeight: uint = DEFAULT_HEIGHT, color: uint = defaultColor, fontSize: uint = defaultFontSize )
Retrieve the current script text.
public function get text():String
Change the callback function called when the script is changed.
public function set changeHandler( changeHandlerFunction: Function ):void
Change the callback function called when a keyboard button is pressed.
public function set keyDownHandler( keyDownHandlerFunction: Function ):void
Displays the top of the script that is the home position.
public function home():void
Sets the scripting language for the text field.
public function set language( scriptLanguageName: String ):void
Syntax highlights by setting text formats on the script field text.
private function syntaxHighlight():void
The text in the input field has been changed
private function inputChangeHandler( event: Event ):void
A keyboard key has been pressed in the input field.
private function inputKeyDownHandler( event: KeyboardEvent ):void
The user has scrolled the text in the input field.
private function scrollHandler( event: Event ):void
The user has manipulated the scrollbar position.
private function scrollbarHandler( newPosition: Number ):void
Sets the state of the widget to active or inactive.
public function set active( state: Boolean ):void
Activates the widget, adds its event listeners
private function activate():void
Disactivates the widget, removes its event listeners
private function disactivate():void
Dispose of all resources used or referenced in the instance.
public function dispose():void
Removes used resources, references and graphics
private function destructor():void
Register the owner of a widget.
public function register( owner: String ):void