Start the Flash program. Click "New" from the File menu on the main Flash menu bar. Click the file type "Flash File(ActionScript 3.0)" from the New Document dialog box that appears. Click the "OK" button to close the dialog box.
Select the "Actions" option from the Window menu on the main Flash menu bar to open the Actions editor. Position your mouse cursor on the first line of the Actions editor. Click your mouse button and type in the following code to create an input TextField that will be used to type text that you want to save in a new file:
var saveText:TextField = new TextField();
saveText.type =TextFieldType.INPUT;
Type the following code, starting at the next line in the Actions editor, to draw a border around the TextField, position the TextField on the flash stage at coordinates (30,100), set the width of the TextField to 200 pixels, allow carriage returns when typing in the TextField and place the TextField on the Flash stage when the Flash program is played:
saveText.border = true;
saveText.x =30;
saveText.y =100;
saveText.width = 200;
saveText.multiline = true;
addChild(saveText);
Type the following code, starting at the next line in the Actions editor, to place a button, drawn with a black pixel border of 4 pixels, filled with the color red, positioned on the Flash stage at coordinates (350, 200) and with a height of 50 pixels and a width of 20 pixels:
var myButton:MovieClip = new MovieClip();
myButton.graphics.lineStyle(4);
myButton.graphics.beginFill(0xFF0000);
myButton.graphics.drawRect(350, 200, 50, 20);
myButton.graphics.endFill();
addChild(myButton);
Type the following code, starting at the next line in the Actions editor, to declare a FileReference object that will be used to access the file saving and loading methods of the FileReference class:
var MyFile:FileReference = new FileReference();
Type the following code, starting at the next line in the Actions editor, to add an event listener to myButton so that when the button is clicked with the Mouse the save file dialog box appears on the stage and the file saved will save the text contents of the text typed into the TextField to a new file:
myButton.addEventListener(MouseEvent.CLICK, saveFile_fn);
function saveFile_fn(e:MouseEvent): void {
MyFile.save(saveText.text);
};
Copy and paste the following code into your Actions editor if you want to ensure that the save new file feature of this Flash word processing program is error free.
var saveText:TextField = new TextField();
saveText.type =TextFieldType.INPUT;
saveText.border = true;
saveText.x =30;
saveText.y =100;
saveText.width = 200;
saveText.multiline = true;
addChild(saveText);
var myButton:MovieClip = new MovieClip();
myButton.graphics.lineStyle(4);
myButton.graphics.beginFill(0xFF0000);
myButton.graphics.drawRect(350, 200, 50, 20);
myButton.graphics.endFill();
var MyFile:FileReference = new FileReference();
addChild(myButton);
myButton.addEventListener(MouseEvent.CLICK, saveFile_fn);
function saveFile_fn(e:MouseEvent): void {
MyFile.save(saveText.text);
};
Click the "TestMovie" option in the Control menu on the main Flash menu bar. Type some text into the TextField and click the red button on the stage to save the text in the TextField to a new file. Type in the name of your new file in the "file name" text box in the Save dialog box that appears, then press the "OK" button to save the file. Open up the file with your text editor if you want to see the text you typed in the actual saved file.