David - here is a class I wrote which I use all the time for working
with XML. It's a slightly different approach I prefer, where the class
listens for the load to complete, and then creates a public XML property
of the data you can get once the load is done.  Here is the class and
the associated custom event:

package utils 
{
        import events.XMLFileLoaderEvent;
        import flash.events.Event;
        import flash.events.EventDispatcher;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        
        /**
         * ...
         * @author Jason Merrill - Bank of America
         */
        public class XMLFileLoader extends EventDispatcher
        {
                public var xml:XML;
                
                private var _xmlURL:String;
                private var _urlLoader:URLLoader;
                
                public function XMLFileLoader(xmlURL:String) 
                {
                        _xmlURL = xmlURL;
                        _urlLoader = new URLLoader(new
URLRequest(_xmlURL));
                        _urlLoader.addEventListener(Event.COMPLETE,
onXMLLoaded); 
                }
                
                private function onXMLLoaded(event:Event):void
                {
                        xml = new XML(event.target.data);
                        dispatchEvent(new
XMLFileLoaderEvent(XMLFileLoaderEvent.LOAD_COMPLETE));
                }
                
        }
        
}

//Custom event

package events
{
        /**
        * ...
        * @author Jason Merrill - Bank of America
        */
        import flash.events.Event;
        
        public class XMLFileLoaderEvent extends Event
        {
                public static var LOAD_COMPLETE:String = "my_event";
                
                public function XMLFileLoaderEvent (type:String,
bubbles:Boolean=false, cancelable:Boolean=false)
                {
                        super(type, bubbles, cancelable);
                }
                
                public override function clone():Event 
                {
                        return new XMLFileLoaderEvent(type, bubbles,
cancelable);
                }
                
                public override function toString():String 
                { 
                        return formatToString("XMLFileLoaderEvent",
"type", "bubbles", "cancelable", "eventPhase"); 
                }
                
        }

}


Jason Merrill 

 Bank of  America  Global Learning 
Learning & Performance Soluions

Join the Bank of America Flash Platform Community  and visit our
Instructional Technology Design Blog
(note: these are for Bank of America employees only)






-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of David
Hunter
Sent: Thursday, November 19, 2009 11:51 AM
To: flashcoders@chattyfig.figleaf.com
Subject: RE: [Flashcoders] OOP and XML


thanks greg, and nice to know that either way is ok. don't want to start
down bad habits already!
i've got it working now with a custom event and a little extra help from
this as well:
http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-e
vents/
cheers.


> Date: Thu, 19 Nov 2009 10:53:18 -0500
> Subject: Re: [Flashcoders] OOP and XML
> From: breakfastcof...@gmail.com
> To: flashcoders@chattyfig.figleaf.com
> 
> either way works... its a 6 of one half a dozen of another type
situation
> 
> so you could say
> 
>     dispatchEvent(Event.COMPLETE) from your XMLLoader class and put
the data
> into a public var that your class listening can access.
> 
> Or you could make a custom event like this
> 
>     dispatchEvent(new XMLEvent(XMLEvent.DATA_LOADED, loader.data));
> 
> where you send in the data into a custom event u make
> 
> hope this makes sense
> 
> greg
> 
> On Thu, Nov 19, 2009 at 10:38 AM, David Hunter
<davehunte...@hotmail.com>wrote:
> 
> >
> > thanks Henrik,
> > are you saying that i need to create a custom event class and
dispatch an
> > event from that class? otherwise how else could i attach the data to
a
> > dispatched event?
> > or do you mean to dispatch an existing event type so when fired the
> > DocumentClass will go into the XMLLoaderClass and grab a public var
> > containing the data?
> > i have never dispatched events before, so i guess i'll have to look
into
> > it.
> > i have posted my two classes on pastebin to look at:
> > http://pastebin.com/m4ba8e745
> > cheers
> > > Date: Thu, 19 Nov 2009 13:58:45 +0100
> > > From: he...@henke37.cjb.net
> > > To: flashcoders@chattyfig.figleaf.com
> > > Subject: Re: [Flashcoders] OOP and XML
> > >
> > > Dispatch an event when the data is ready and have the main code
listen
> > > for the event.
> > > _______________________________________________
> > > Flashcoders mailing list
> > > Flashcoders@chattyfig.figleaf.com
> > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> >
> > _________________________________________________________________
> > Got more than one Hotmail account? Save time by linking them
together
> >
> >
http://clk.atdmt.com/UKM/go/186394591/direct/01/________________________
_______________________
> > Flashcoders mailing list
> > Flashcoders@chattyfig.figleaf.com
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
                                          
_________________________________________________________________
Add your Gmail and Yahoo! Mail email accounts into Hotmail - it's easy
http://clk.atdmt.com/UKM/go/186394592/direct/01/________________________
_______________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to