Quantcast
Channel: Adobe Community : Popular Discussions - AIR Development
Viewing all articles
Browse latest Browse all 24121

Download/Save/Read to ApplicationStorageDirectory

$
0
0

Hello all,

 

I am trying to download a file, and save it to the applicationStorageDirectory. I then would like to immediately read the file, and input a text field into m1_txt.

I have been scratching my head a little towards this, and the code below doesn't seem to work. ANY SUGGESTIONS?

 

Thank you.




////check date

var go_month = new Date();

var month = go_month.getMonth();

 

////current mainframe (date)

var datadd:Number = Object(root).currentFrame;

 

////download prayer file

var url:String = "http://website.org/prayers/"+month+".xml";

var urlRequest:URLRequest = new URLRequest(url);

var urlLoader:URLLoader = new URLLoader();

urlLoader.dataFormat = URLLoaderDataFormat.BINARY;

urlLoader.addEventListener(Event.COMPLETE, proceed);

urlLoader.load(urlRequest);

 

 

function proceed(event:Event):void {

var bytes:ByteArray = urlLoader.data;
var file:File = File.applicationStorageDirectory.resolvePath("prayers/"+month+".xml");
var filestream:FileStream = new FileStream();
filestream.addEventListener(Event.CLOSE, loadremoteprayer);
filestream.open(file, FileMode.WRITE);
filestream.writeBytes(bytes);
filestream.close();
}

////load prayer file

function loadremoteprayer(e:Event):void {

var prayers:File = File.applicationStorageDirectory.resolvePath("prayers/"+month+".xml");
var prayertext:XML;

    var s:FileStream = new FileStream()

    s.open(prayers, FileMode.READ);

    prayertext = XML(s.readUTFBytes(s.bytesAvailable));

    s.close();

var currenttext = "m" + datadd;
m1_txt.text = prayertext[currenttext];

}


Viewing all articles
Browse latest Browse all 24121

Latest Images

Trending Articles



Latest Images