WHAT'S NEW?
Loading...

class load xml




/*
*class ini bersifat opensource tidak untuk diperjual belikan,
*walaupun demikian kami menghargai jika anda menghargai sumbernya
*------------Ricko Nada www.pustakaflash.com----------------------*
*Main class
package 
{
 import flash.display.Sprite;
 import com.PustakaFlash.loadXml;
 import flash.events.Event;

 public class Main extends Sprite
 {
  private var xml:XML;
  private var ld:loadXml;

  public function Main()
  {
   if (stage)
   {
    init();
   }
   else
   {
    addEventListener(Event.ADDED_TO_STAGE, init);
   }

  }
  private function init(e:Event = null):void
  {
   removeEventListener(Event.ADDED_TO_STAGE, init);
   ld=new loadXml("tes.xml");
   ld.addEventListener(loadXml.COMPLETE, loadXmlCompleteHandler);
   ld.addEventListener(loadXml.ERROR, loadXmlErrorHandler);
   ld.addEventListener(loadXml.SecurityError, loadXmlErrorHandler);
   ld.addEventListener(loadXml.XML_ParseError, loadXmlErrorHandler);

   // entry point

  }
  private function loadXmlErrorHandler(e:Event):void
  {
   switch (e.type)
   {
    case loadXml.ERROR :
     trace("file xml gak ketemu bos!!!");
     break;
    case loadXml.SecurityError :
     trace("SecurityError");
     break;
    case loadXml.XML_ParseError :
     trace("XML_ParseError");
     break;

   }
  }
  private function loadXmlCompleteHandler(e:Event):void
  {
   ld.removeEventListener(loadXml.COMPLETE, loadXmlCompleteHandler);
   ld.removeEventListener(loadXml.ERROR, loadXmlErrorHandler);
   xml = ld.data;
   trace(xml);//output data xml
   tes.text = xml..harga;
  }
 }
}
*TimelineScript(primitive technic) :)
import com.PustakaFlash.loadXml;
var xml:XML;
var ld:loadXml = new loadXml("tes.xml");
ld.addEventListener(loadXml.COMPLETE, loadXmlCompleteHandler);
ld.addEventListener(loadXml.COMPLETE, loadXmlCompleteHandler);
ld.addEventListener(loadXml.ERROR, loadXmlErrorHandler);
ld.addEventListener(loadXml.SecurityError, loadXmlErrorHandler);
ld.addEventListener(loadXml.XML_ParseError, loadXmlErrorHandler);

function loadXmlCompleteHandler(e:Event):void
{
 xml = ld.data;
 trace(ld.data);
 td.text = xml..harga;
}

function loadXmlErrorHandler(e:Event):void
{
 switch (e.type)
 {
  case loadXml.ERROR :
   trace("file xml gak ketemu bos!!!");
   break;
  case loadXml.SecurityError :
   trace("SecurityError");
   break;
  case loadXml.XML_ParseError :
   trace("XML_ParseError");
   break;

 }
}

stop();
*/
package com.PustakaFlash
{
 import flash.events.Event;
 import flash.events.EventDispatcher;
 import flash.events.IOErrorEvent;
 import flash.net.URLLoader;
 import flash.net.URLRequest;
 import flash.events.SecurityErrorEvent;

 /**
   * ...
   * @author Ricko www.pustakaflash.com
   */
 public class loadXml extends EventDispatcher
 {
  public static const COMPLETE:String = "loadComplete";
  public static const ERROR:String = "loadError";
  public static const SecurityError:String = "xml_SecurityError";
  public static const XML_ParseError:String = "XML_ParseError";

  private var l:URLLoader = new URLLoader();
  private var d:XML;
  public function loadXml(p:String):void
  {
   l.load(new URLRequest(p));
   l.addEventListener(Event.COMPLETE, t);
   l.addEventListener(IOErrorEvent.IO_ERROR, s);
   l.addEventListener(SecurityErrorEvent.SECURITY_ERROR,o);
  }
  private function s(e:IOErrorEvent):void
  {
   dispatchEvent(new Event(ERROR));
  }
  private function t(e:Event):void
  {
   try
   {
    d = new XML(l.data);
    dispatchEvent(new Event(COMPLETE));
    removeEventListener(Event.COMPLETE, t);
    removeEventListener(IOErrorEvent.IO_ERROR, s);
    removeEventListener(SecurityErrorEvent.SECURITY_ERROR, o);
   }
   catch (e:Error)
   {
    dispatchEvent(new Event(XML_ParseError));
   }

  }
  /**
  *securityerror
  */
  private function o(e:Event):void
  {
   dispatchEvent(new Event(SecurityError));
  }
  /**
  * Get xml data
  */
  public function get data():XML
  {
   return d;
  }
 }
}

0 komentar:

Post a Comment