Ver Mensaje Individual
  #7 (permalink)  
Antiguo 29/12/2009, 13:43
Avatar de Lynxcraft
Lynxcraft
 
Fecha de Ingreso: noviembre-2007
Ubicación: yecla murcia
Mensajes: 1.346
Antigüedad: 16 años, 5 meses
Puntos: 51
Respuesta: addEventListener + return

yo tengo un código mas complejo pero me ayuda ya que es muy rápido de emplear una ves colocado


as

Código PHP:
package com.cfx.basic{
    
import flash.events.*;
    
import flash.net.*;
    public class 
Xml {
        private static  const 
FuncObj:Array=['COMPLETE','PROGRESS','ERROR','HTTP_STATUS'];
        public static function 
load(url:String,Func:Object=null):void {
            var 
func:Array=new Array;
            if (
Func == null) {
                for (var 
i:int=0i<FuncObj.lengthi++) {
                    
func[FuncObj[i]]=function(...rest){};
                }
            } else {
                for (var 
j:int=0j<FuncObj.lengthj++) {
                    if (
Func[FuncObj[j]] is Function) {
                        
func[FuncObj[j]]=Func[FuncObj[j]];
                    } else {
                        
func[FuncObj[j]]=function(...rest){};
                    }
                }
            }
            var 
loadXML:URLLoader=new URLLoader();
            
configureListeners(loadXML);
            
loadXML.load(new URLRequest(url));
            try {
                
loadXML.load(new URLRequest(url));
            } catch (
error:Error) {
                
func.ERROR('Carga Fallida');
            }
            function 
configureListeners(dispatcher:IEventDispatcher):void {
                
dispatcher.addEventListener(Event.COMPLETEcompleteHandler);
                
dispatcher.addEventListener(ProgressEvent.PROGRESSprogressHandler);
                
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERRORsecurityErrorHandler);
                
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUShttpStatusHandler);
                
dispatcher.addEventListener(IOErrorEvent.IO_ERRORioErrorHandler);

            }
            function 
completeHandler(event:Event):void {
                var 
loader:URLLoader URLLoader(event.target);
                
func.COMPLETE(XML(loader.data));
            }
            function 
progressHandler(event:ProgressEvent):void {
                
func.PROGRESS(event.bytesLoaded,event.bytesTotal);
            }
            function 
securityErrorHandler(event:SecurityErrorEvent):void {
                
func.ERROR(String(event));
            }
            function 
httpStatusHandler(event:HTTPStatusEvent):void {
                
func.HTTP_STATUS(event);
            }
            function 
ioErrorHandler(event:IOErrorEvent):void {
                
func.ERROR(event);
            }
        }
    }


ejemplo

Código PHP:
package {
    
import com.cfx.basic.Xml;
    public class 
ejemploXML {
        public var 
miXml:XML;
        public function 
ejemploXML ():void {
            
Xml.load('ejemplo.xml',{COMPLETE:loadXML});
            
        }
        public function 
loadXML(xml:XML):void {
            
miXml=xml;
            
trace(xml)
        }
        
    }

una ves que ha completado la carga devuelve el xml y ejecuta la función que quieras
__________________
Sobran las ideas cuando faltan ganas de trabajar en ellas
Lynxcraft