Pages

Tuesday, January 3, 2012

AS3: Xml Stack Loader

The class is used to load multiple xml/text files in a queue.

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
package
{
 import CSingleFileLoader;
 
 /**
  * @file CXmlStackLoader.as
  * @author Abhishek Kumar
  */
 public class CXmlStackLoader
 {
  public var prepare:Function;
  public var progress:Function;
  public var proceed:Function;
  
  public function CXmlStackLoader()
  {
   trace ("CXmlStackLoader -> constructor");
  }
  
  public function retrieve(src:String):void
  {
   trace ("CXmlStackLoader -> retrieve src", src);
   var oSingleFileLoader:CSingleFileLoader = new CSingleFileLoader();
   oSingleFileLoader.prepare = prepare;
   oSingleFileLoader.progress = progress;
   oSingleFileLoader.proceed = onLoad_XmlStack;
   oSingleFileLoader.retrieve(src);
  }  
  
  private function onLoad_XmlStack(data:String):void
  {
   trace ("CXmlStackLoader -> onLoad_XmlStack");
   var list:XMLList = new XMLList(data);
   var elenco:Array = [];
   
   for(var i:int=0, len:int=list.length(); i<len; i++)
    if(String(list.file[i].@enabled).toLowerCase() == 'true')
     elenco.push(list.file[i].@src);
   
   var oMultipleFileLoader:CMultipleFileLoader = new CMultipleFileLoader();
   oMultipleFileLoader.prepare = prepare;
   oMultipleFileLoader.progress = progress;
   oMultipleFileLoader.proceed = onComplete_XmlStack;
   oMultipleFileLoader.retrieve(elenco);
  }
  
  private function onComplete_XmlStack(list:Array):void
  {
   trace ("CXmlStackLoader -> onComplete_XmlStack");
   proceed(list);
  }  
 }
}

No comments:

Post a Comment