Pages

Tuesday, January 3, 2012

AS3: Multiple File Loader

Single file loader for type like txt, xml, etc.

SOURCE CODE
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package
{
 import CSingleFileLoader;
 
 /**
  * @file CMultipleFileLoader.as
  * @author Abhishek Kumar
  */
 public class CMultipleFileLoader
 {
  public var prepare:Function;
  public var progress:Function;
  public var proceed:Function;
  
  private var filelist:Array;
  private var stack:Array;
  private var count:int;
  private var limit:int;
  
  public function CMultipleFileLoader()
  {
   trace ("CMultipleFileLoader -> constructor");
  }
  
  public function retrieve(list:Array):void
  {
   trace ("CMultipleFileLoader -> retrieve");
   // initialize
   filelist = list;
   stack = [];
   count = 0;
   limit = filelist.length;
   // start loading
   loadAllXml();
  } 
  
  private function loadAllXml():void
  {
   trace ("CMultipleFileLoader -> loadAllXml");
   if(count < limit)
    loadXml(filelist[count]);
   else
    proceed(stack);
  }
  
  private function loadXml(src:String):void
  {
   trace ("CMultipleFileLoader -> loadXml src:", src);
   var oSingleFileLoader:CSingleFileLoader = new CSingleFileLoader();
   oSingleFileLoader.prepare = prepare;
   oSingleFileLoader.progress = progress;
   oSingleFileLoader.proceed = onLoad_Xml;
   oSingleFileLoader.retrieve(src);
  }
  
  private function onLoad_Xml(data:String):void
  {
   trace ("CMultipleFileLoader -> onLoad_Xml data");
   stack.push(new XMLList(data));
   count++;
   loadAllXml();
  } 
 }
}

No comments:

Post a Comment