Flash Text Database Tutorial: Database Structure after Load into Flash Movie
This is the first Flash ActionScript tutorial of basic text database manipulation. Let's examine if there is any changes of the database structure after loading into a Flash Movie.
Flash Tutorial Content:
The first step is try to use ActionScript to load the external text file (database) into the Flash Movie and examine the structure of the database.
You should notice that an empty line is inserted betwen each record after the database was loaded into the Flash Movie.
The complete Flash Movie is shown as above, you may try how it works before you start this tutorial.
Flash ActionScript Codes:
//You can declare the url of the text file as string
//so that you can use it later
var url:String = "staff.txt";
//Create a URLLOader object with the name myLoader
var myLoader:URLLoader = new URLLoader();
//Load the text file by using URLRequest
//Can be local file or URL of webpage
myLoader.load(new URLRequest(url));
//Listen when the loading of text file COMPLETE
//Call the loadComplete function when the loading COMPLETE
myLoader.addEventListener(Event.COMPLETE, loadComplete);
//Declare some variables to use later
var myString:String;
function loadComplete(evt:Event) {
myString = evt.target.data;
//Display the file content
output_txt.text = myString;
//Remove Listener that no longer in use
myLoader.removeEventListener(Event.COMPLETE, loadComplete);
}
//////////////////////////////
///// ERROR HANDLING /////
/////////////////////////////
// Listen error events for the loading process
// Call loadError function in case an error appear
myLoader.addEventListener(IOErrorEvent.IO_ERROR, loadError1)
myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadError1)
myLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, loadError2)
function loadError1(event:ErrorEvent):void {
output_txt.text = "Sorry that there is an error during the loading of an external text file. The error is:" + "\n" + event.text;
function loadError2(event:HTTPStatusEvent):void {
output_txt.text = "Sorry that there may be an error during the loading of an external text file. The error is:" + "\n" + event.status;
Download Flash Source File:
Remarks:
This Flash ActionScript tutorial examine the database structure after loaded into Flash Movie.