Skip to content

Instantly share code, notes, and snippets.

@mki
Created August 29, 2012 19:48
Show Gist options
  • Save mki/3517873 to your computer and use it in GitHub Desktop.
Save mki/3517873 to your computer and use it in GitHub Desktop.
FileReference example for package upload files (see more at http://mkifiles.ru/?p=1518)
//Функция вызывается при клике по кнопке
public function onClick(event:Event) : void
{
// Пробегаем по массиву композиций и формируем массив для
// загрузки "urlLoader"
while (i < this.arrMusic.length)
{
// Формируем Request
var urlRequest:URLRequest = new URLRequest();
urlRequest.url = ''; // ссылка куда грузим файл
urlRequest.method = URLRequestMethod.POST;
// Массив с загружаемыми файлами
this.urlLoader[i] = (this.arrMusic)[i].fileRef;
this.urlLoader[i].addEventListener(Event.COMPLETE, completeHandler);
// Массив Request-ов для загрузки
this.uploadingNow[i] = new Array();
this.uploadingNow[i]['request'] = urlRequest;
i++;
}
// Запускаем загрузку первого файла
try
{
this.urlLoader[0].upload(this.uploadingNow[0]['request'],'upload_0');
}
catch (error:Error){}
return;
}
// Функция вызывается после завершения загрузки файла
private function completeHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
var songs:Array = this.uploadingNow;
var _in:int = 0;
if (songs.length > 0) {
while ( _in < songs.length ) {
if (songs[_in]['uploaded'] != true) {
// Запускаем следующий файл. Клика пользователя для запуска не нужно.
this.urlLoader[_in].upload(this.uploadingNow[_in]['request'],'upload_'+_in);
}
_in++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment