The third Stage…

The error that I mention in the previous post is displaying the amount of money is fixed by using code (Math.round(totalCoins*100)/100).

And what I need to do at this stage is writing code to store data and loading back the data.
I have used the FileStream to write data to a text file,

import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;

//Create a file.
var file:File = File.documentsDirectory.resolvePath(“J:/…/…/… Multimedia Systems/…/…/money_txt.txt”);

//Create file stream to write data to file
var stream:FileStream = new FileStream();

stream.open( file, FileMode.WRITE );

//write data to file
stream.writeUTFBytes( money_txt.text=”You have:”+(Math.round(totalCoins*100)/100)+”dollars” );

//Close the WRITE file stream
stream.close();

And use text loader to read the stored data from the text file.
The code are:
//the path should be a problem of this application but I know how to fix it yet….
var PATH:String = “J:/…/…/… Multimedia Systems/…/…/money_txt.txt”;
var urlRequest:URLRequest = new URLRequest(PATH);
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT; // default
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
urlLoader.load(urlRequest);

function urlLoader_complete(evt:Event):void {
money_txt.text = urlLoader.data;
}

displayData

At this Stage they are all work when using Ctrl+Enter to test the moive, but after I quit the program and re-open swf file, all functions are not working expect loading data from the text…I hope I can fix it up in the next few days.

Next Stage: apply graphics and further development

~ by wingcl on September 24, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.