• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Download/Save/Read to ApplicationStorageDirectory

Explorer ,
Jan 19, 2015 Jan 19, 2015

Copy link to clipboard

Copied

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];

}

TOPICS
Development

Views

170

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines