TextEditor (Adobe AIR only)

Package:
Class:
Inheritance:
biz.flashscript.adobeAir
public class TextEditor
Sprite
The TextEditor class allows to create and save text from textfields on the user's harddrive. Use the constructor to create a new TextEditor().
Public Properties
Property Defined By
myText : Object
The name of the textfield to write and save the text.
TextEditor
fileType : String
The extension of the text to save. Default is .txt.
TextEditor
Public Methods
Method Defined By
TextEditor()
Creates a new instance of the TextEditor class.
TextEditor
saveHandler():void
Saving the edited text directly if the textfile exists or saving in a new file if not.
TextEditor
browseFile():void
To browse for a file to select.
TextEditor
newfileHandler(alertText:Object=null):void
Creates a new file.
TextEditor
closeTheFile():void
Creates an open textfile.
TextEditor
Events
Event Defined By

textStatus

This event is dispatched when the file was saved.

TextEditor

saveActivated

This event is dispatched the user writes in the textfield.

TextEditor

fileOpen

This event is dispatched when a file is open.

TextEditor

fileClosed

This event is dispatched when a file is closed.

TextEditor
All inherited events for the EventDispatcher class. N/A
Property Detail
myText property
myText:Object [read-write]

The name of the textfield to write and save the text.

Implementation

public function get myText():Object
public function set myText(value:Object):void
fileType property
fileType:String [read-write]

The extension of the text to save. Default is .txt. Can be multiple extensions ("*.as;*.css;*.html;*.txt;*.xml").

Implementation

public function get fileType():String
public function set fileType(value:String):void
Constructor Detail
TextEditor ()  Constructor
public function TextEditor()
Intializes a new TextEditor instance.
Method Detail

TextEditor()  method
public function TextEditor():void

Creates a new instance of the TextEditor.

saveHandler()  method
public function saveHandler():void

Saving the edited text directly if the textfile exists or saving in a new file if the file does not exist.

browseFile()  method
public function browseFile():void

To browse for a file to select.

newfileHandler()  method
public function newfileHandler(alertText:Object=null):void

Create a new file.

Parameters

  • alertText:Object=null ____ Optional, TextField or TextArea to notify user. Default is null.

closeTheFile()  method
public function closeTheFile():void

Closes an open file. Should be used with Eventhandlers as shown in the example below.

Event Detail

textStatus event

Event Object Type: biz.flashscript.adobeAir.TextEditor
Event.type property = biz.flashscript.adobeAir.TextEditor.TEXT_STATUS

Dispatched when the file was saved.

saveActivated event

Event Object Type: biz.flashscript.adobeAir.TextEditor
Event.type property = biz.flashscript.adobeAir.TextEditor.SAVE_ACTIVATED

Dispatched when the writes for the first time in the textfield.

fileOpen event

Event Object Type: biz.flashscript.adobeAir.TextEditor
Event.type property = biz.flashscript.adobeAir.TextEditor.FILE_OPEN

Dispatched when a file is opened either an existing or new one.

fileClosed event

Event Object Type: biz.flashscript.adobeAir.TextEditor
Event.type property = biz.flashscript.adobeAir.TextEditor.FILE_CLOSED

Dispatched when a file is closed.

Examples
Create a new fla file and name it TexteditorExample.fla. Set the Publish settings to Adobe Air and put the name TexteditorExample in the class file. Place the fla in the same folder as the biz folder. Put four CustomButton components (newFile, openfile, saveasFile and closeFile), one large size TextArea (myText) and a single line TextArea component (action) on stage. Then create an Actionscript file, name it TexteditorExample.as and place this script.
package 
{
	import flash.display.Sprite;
	import biz.flashscript.adobeAir.TextEditor;
	import flash.events.*;
	import fl.controls.TextArea;
	import biz.flashscript.components.buttons.CustomButton;

	public class TexteditorExample extends Sprite
	{
		public var newFile:CustomButton;
		public var openFile:CustomButton;
		public var saveasFile:CustomButton;
		public var closeFile:CustomButton;
		public var myText:TextArea;
		public var action:TextArea;
		private var ted:TextEditor;
		public function TexteditorExample ():void
		{
			ted = new TextEditor();
			ted.myText = myText;
			ted.fileType = "*.as;*.css;*.html;*.txt;*.xml";
			addChild (ted);
			ted.addEventListener (TextEditor.TEXT_STATUS, statusHandler);
			ted.addEventListener (TextEditor.SAVE_ACTIVATED, actsaveHandler);
			ted.addEventListener (TextEditor.FILE_OPEN, openHandler);
			ted.addEventListener (TextEditor.FILE_CLOSED, closeHandler);
			saveasFile.label = "Save file";
			saveasFile.enabled = false;
			saveasFile.addEventListener (MouseEvent.CLICK,saveHandler);
			newFile.label = "New File";
			newFile.buttonMode = true;
			newFile.addEventListener (MouseEvent.CLICK,newfileHandler);
			openFile.label = "Open File";
			openFile.buttonMode = true;
			openFile.addEventListener (MouseEvent.CLICK,browseFile);
			closeFile.label = "Close File";
			closeFile.buttonMode = true;
			closeFile.enabled = false;
			closeFile.addEventListener (MouseEvent.CLICK,closeTheFile);
		}
		private function browseFile (event:Event):void
		{
			ted.browseFile ();
		}
		private function newfileHandler (event:Event):void
		{
			ted.newfileHandler (action);
			closeFile.enabled = true;
			saveasFile.enabled = true;
		}
		private function saveHandler (event:MouseEvent=null):void
		{
			ted.saveHandler ();
		}
		private function closeTheFile (event:Event):void
		{
			ted.closeTheFile ();
		}
		private function openHandler (event:Event):void
		{
			closeFile.enabled = true;
		}
		private function closeHandler (event:Event):void
		{
			closeFile.enabled = false;
			saveasFile.enabled = false;
		}
		private function statusHandler (event:Event):void
		{
			action.text = "Changes and file were saved.";
			saveasFile.enabled = false;
		}
		private function actsaveHandler (event:Event):void
		{
			saveasFile.enabled = true;
		}
	}
}