| 1 |
/** |
|---|
| 2 |
* ListURLLoader |
|---|
| 3 |
* |
|---|
| 4 |
* Licensed under the MIT License |
|---|
| 5 |
* |
|---|
| 6 |
* Copyright (c) 2009 BOONDOCK RADIO (boondockradio.net) |
|---|
| 7 |
* |
|---|
| 8 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 9 |
* of this software and associated documentation files (the "Software"), to deal |
|---|
| 10 |
* in the Software without restriction, including without limitation the rights |
|---|
| 11 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 12 |
* copies of the Software, and to permit persons to whom the Software is |
|---|
| 13 |
* furnished to do so, subject to the following conditions: |
|---|
| 14 |
* |
|---|
| 15 |
* The above copyright notice and this permission notice shall be included in |
|---|
| 16 |
* all copies or substantial portions of the Software. |
|---|
| 17 |
* |
|---|
| 18 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 19 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 20 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 21 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 22 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 23 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 24 |
* THE SOFTWARE. |
|---|
| 25 |
* |
|---|
| 26 |
* |
|---|
| 27 |
* 複数のデータを一度に読み込むクラスです。 |
|---|
| 28 |
* |
|---|
| 29 |
* [ sample code ] |
|---|
| 30 |
* |
|---|
| 31 |
* var listURLLoader:ListURLLoader = new ListURLLoader(); |
|---|
| 32 |
* listURLLoader.list = [ "aaa.xml", "bbb.xml", "ccc.xml" ]; |
|---|
| 33 |
* listURLLoader.addEventListener(Event.INIT, function():void { |
|---|
| 34 |
* listURLLoader.removeEventListener(Event.INIT, arguments.callee); |
|---|
| 35 |
* trace(listURLLoader.data); |
|---|
| 36 |
* }); |
|---|
| 37 |
* listURLLoader.start(); |
|---|
| 38 |
*/ |
|---|
| 39 |
|
|---|
| 40 |
package net.boondockradio.load |
|---|
| 41 |
{ |
|---|
| 42 |
import flash.errors.IOError; |
|---|
| 43 |
import flash.events.Event; |
|---|
| 44 |
import flash.events.EventDispatcher; |
|---|
| 45 |
import flash.events.IOErrorEvent; |
|---|
| 46 |
import flash.net.URLLoader; |
|---|
| 47 |
import flash.net.URLRequest; |
|---|
| 48 |
|
|---|
| 49 |
public class ListURLLoader extends EventDispatcher |
|---|
| 50 |
{ |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
/** |
|---|
| 54 |
* write only member |
|---|
| 55 |
*/ |
|---|
| 56 |
private var _list:Array; |
|---|
| 57 |
public function set list (value:Array):void |
|---|
| 58 |
{ |
|---|
| 59 |
_list = value; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
/** |
|---|
| 63 |
* read only member |
|---|
| 64 |
*/ |
|---|
| 65 |
private var _data:Array; |
|---|
| 66 |
public function get data ():Array { return _data; } |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
// use for URLLoader List |
|---|
| 70 |
private var _loadList:Array = new Array(); |
|---|
| 71 |
|
|---|
| 72 |
// complete count |
|---|
| 73 |
private var _cnt:int = 0; |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
/** |
|---|
| 77 |
* constructor |
|---|
| 78 |
*/ |
|---|
| 79 |
public function ListURLLoader() {} |
|---|
| 80 |
|
|---|
| 81 |
/** |
|---|
| 82 |
* load start |
|---|
| 83 |
*/ |
|---|
| 84 |
public function start():void |
|---|
| 85 |
{ |
|---|
| 86 |
if(_list == null) { |
|---|
| 87 |
throw new ArgumentError("読み込み対象がありません。 / doesn't have load target."); |
|---|
| 88 |
return; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
_init(); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
/** |
|---|
| 97 |
* initialize |
|---|
| 98 |
*/ |
|---|
| 99 |
private function _init():void |
|---|
| 100 |
{ |
|---|
| 101 |
for(var i:int = 0; i < _list.length; i++) { |
|---|
| 102 |
_loadList[i] = new URLLoader(); |
|---|
| 103 |
_loadList[i].addEventListener(Event.COMPLETE, _onComplete); |
|---|
| 104 |
_loadList[i].addEventListener(IOErrorEvent.IO_ERROR, _onError); |
|---|
| 105 |
_loadList[i].load(new URLRequest(_list[i])); |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
/** |
|---|
| 110 |
* load complete |
|---|
| 111 |
*/ |
|---|
| 112 |
private function _onComplete(e:Event):void |
|---|
| 113 |
{ |
|---|
| 114 |
e.target.removeEventListener(e.type, arguments.callee); |
|---|
| 115 |
|
|---|
| 116 |
_cnt++; |
|---|
| 117 |
|
|---|
| 118 |
if(_loadList.length == _cnt) { |
|---|
| 119 |
_data = new Array(); |
|---|
| 120 |
for(var i:int = 0; i < _loadList.length; i++) { |
|---|
| 121 |
_data[i] = _loadList[i].data; |
|---|
| 122 |
} |
|---|
| 123 |
dispatchEvent(new Event(Event.INIT)); |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
/** |
|---|
| 128 |
* IO Error |
|---|
| 129 |
*/ |
|---|
| 130 |
private function _onError(e:IOErrorEvent):void |
|---|
| 131 |
{ |
|---|
| 132 |
e.target.removeEventListener(e.type, arguments.callee); |
|---|
| 133 |
dispatchEvent(e); |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|