thanks jason

a


On 27 Mar 2008, at 21:30, Merrill, Jason wrote:

Yeah, I mean that's basically how I described it and would do it - there
might be a better way, but that way should work fine for you.

Jason Merrill
Bank of America
GT&O and Risk L&LD Solutions Design & Development
eTools & Multimedia

Bank of America Flash Platform Developer Community


Are you a Bank of America associate interested in innovative learning
ideas and technologies?
Check out our internal  GT&O Innovative Learning Blog & subscribe.






-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf
Of Allandt Bik-Elliott (Receptacle)
Sent: Thursday, March 27, 2008 4:30 PM
To: Flash Coders List
Subject: Re: [Flashcoders] using a class to load data

thanks jason - i've done this and it's working, i just wanted
you to take a look to make sure i've not done it stupidly

CODE
package
{
        //package imports
        import flash.events.*;
        import flash.net.*;
        
        internal class XMLLoader extends EventDispatcher
        {
                // class variable declarations
                private var xmlDoc:XML;
                private var xmlURL:String;
                private var xmlLoader:URLLoader;
                
                public static const COMPLETE:String = "complete";
                
                public function get doc():XML
                {
                        return xmlDoc;
                }
                
                // constructor
                public function XMLLoader(url:String)
                {
                        xmlURL = url;
                        var urlRequest:URLRequest = new
URLRequest(xmlURL);
                        xmlLoader = new URLLoader();
                        
xmlLoader.addEventListener(Event.COMPLETE, completeListener);
                        xmlLoader.load(urlRequest);
                }
                
                private function completeListener(e:Event):void
                {
                        xmlDoc = new XML(xmlLoader.data);
                        dispatchEvent(new Event(XMLLoader.COMPLETE));
                }
        }
}
/CODE

and the function call is

CODE
private var xmlDoc:XML;
private var xmlurl:String;
private var xmlLoader:XMLLoader;

// call to initialiseXML() made in constructor private
function initialiseXML():void {
        xmlLoader = new XMLLoader(xmlurl);              
        xmlLoader.addEventListener(Event.COMPLETE, completeListener); }
                
private function completeListener(e:Event):void {
        xmlDoc = xmlLoader.doc;
        trace (xmlDoc.toXMLString()); //traces xml correctly } /CODE

a



On 27 Mar 2008, at 19:14, Merrill, Jason wrote:

Have your XMLLoader class extend EventDispatcher and have your
XMLLoader class dispatch an event when the load is
complete.  Wherever
your instance of the class is declared, add an event
listener to the
instance and write a function handler. if you need assistance with
setting that up, write back, it's pretty simple.


Jason Merrill
Bank of America
GT&O and Risk L&LD Solutions Design & Development eTools &
Multimedia

Bank of America Flash Platform Developer Community


Are you a Bank of America associate interested in
innovative learning
ideas and technologies?
Check out our internal  GT&O Innovative Learning Blog & subscribe.






-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Allandt Bik-Elliott (Receptacle)
Sent: Thursday, March 27, 2008 2:51 PM
To: flashcoders
Subject: [Flashcoders] using a class to load data

hi guys

i am trying to set up a class to handle my xml (will be
instantiated
for each xml file) but i'm running into a slight problem

here is the class so far:

CODE
package
{
        //package imports
        import flash.events.*;
        import flash.net.*;
        
        internal class XMLLoader
        {
                // class variable declarations
                private var xmlDoc:XML;
                private var xmlURL:String;
                private var xmlLoader:URLLoader;
                
                public function get doc():XML {return xmlDoc;}
                
                // constructor
                public function XMLLoader(url:String)
                {
                        xmlURL = url;
                        var urlRequest:URLRequest = new
URLRequest(xmlURL);
                        xmlLoader = new URLLoader();
                        
xmlLoader.addEventListener(Event.COMPLETE, completeListener);
                        xmlLoader.load(urlRequest);
                }
                
                private function completeListener(e:Event):void
                {
                        xmlDoc = new XML(xmlLoader.data);
                }
        }
}
/CODE

the problem is with timing - from within the XMLLoader()
Class i can
wait for the COMPLETE event to reference the xmlDoc but
how would i
do that from an instance of the class?

for instance if i do the following from my main class i
get a null
object error because it doesn't wait for the data to be loaded
before trying to read it:

CODE
var xmlurl:String = "path/to/xml.xml"; var xmlDoc:XMLLoader = new
XMLLoader(xmlurl); xmlDoc = xmlLoader.doc; trace
(xmlDoc.toXMLString()); /CODE

this would equally apply to an image loader, i guess

thanks in advance
a

Allandt Bik-Elliott
thefieldcomic.com
e [EMAIL PROTECTED]

_______________________________________________
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



_______________________________________________
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



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to