Re: [Flashcoders] Help with listener for custom class (AS3)

2007-09-13 Thread Rob Romanek

Hi Dane,

Here are some thoughts for you to try. First off since you are not  
actually working with a display object you don't need this class to extend  
sprite. The easiest way to give the class the ability to send out events  
is to have it extend EventDispatcher and then you can have it dispatch  
events as required...  here is you sample pared down a bit, just dealing  
with xml


package {
import flash.events.*;
import flash.net.*;
public class fileImports extends EventDispatcher {
public var newStyleSheet:StyleSheet = new StyleSheet();
public var newXML:XML = new XML();
public function fileImports(xmlFile:String):void {
var xmlToLoad:URLRequest=new URLRequest(xmlFile);
var xmlLoader:URLLoader = new URLLoader;

xmlLoader.load(xmlToLoad);
//event listeners
xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);

}

public function xmlLoaded(event:Event):void {
newXML = XML(event.target.data);
dispatchEvent(new Event(Event.COMPLETE));
}
}
}

then in the movie calling the class

var tFile = new fileImports(data/xml/presenter1.xml);
tFile.addEventListener(Event.COMPLETE, xmlDone);
function xmlDone(e:Event){
trace(done);
}

hth,

Rob

On Tue, 11 Sep 2007 15:25:05 -0400, Dane Williams [EMAIL PROTECTED]  
wrote:



My problem is I don't know how to listen to the class
from the main timeline to find out if the class is finished processing  
the
XML. Right now if I try to use fileForThis.newXML I get a value of  
null.
But if I put a trace on newXML in the class, it shows the content of my  
XML

file.
I have gotten this to work on other projects because I haven't tried to  
use

the data immediately - so the data has time to process before it's put
into a text field, etc.
I appreciate any help I can get on this. Thanks!

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


[Flashcoders] Help with listener for custom class (AS3)

2007-09-12 Thread Dane Williams
Greetings All,
I'm trying to do more and more of my projects with external classes and,
along with that, creating classes for routines that I regularly do. I have a
class that reads an XML file and CSS file once it's called. It has worked
fine for the first few projects I used it in. With my recent project, it's
not wanted to behave. The code for the class is as follows:
package {
 import flash.display.Sprite;
 import flash.text.StyleSheet;
 import flash.events.*;
 import flash.net.*;
 public class fileImports extends Sprite {
  public var newStyleSheet:StyleSheet = new StyleSheet();
  public var newXML:XML = new XML();
  public function fileImports(xmlFile:String, cssFile:String):void {
   //load css file
   var cssToLoad:URLRequest=new URLRequest(cssFile);
   var cssLoader:URLLoader = new URLLoader;
   cssLoader.load(cssToLoad);
   //load xml file
   var xmlToLoad:URLRequest=new URLRequest(xmlFile);
   var xmlLoader:URLLoader = new URLLoader;;
   xmlLoader.load(xmlToLoad);
   //event listeners
   xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);
   cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
  }
  public function cssLoaded(event:Event):void {
   newStyleSheet.parseCSS(event.target.data);
  }
  public function xmlLoaded(event:Event):void {
   newXML = XML(event.target.data);
  }
 }
} 
 
I am creating an instance on my main timeline with this:
var fileForThis:fileImports = new
fileImports(courseInfo.xml,styles.css);
 
I am trying to use the data that is coming in with the XML file to populate
some combo boxes. My problem is I don't know how to listen to the class
from the main timeline to find out if the class is finished processing the
XML. Right now if I try to use fileForThis.newXML I get a value of null.
But if I put a trace on newXML in the class, it shows the content of my XML
file.
 
I have gotten this to work on other projects because I haven't tried to use
the data immediately - so the data has time to process before it's put
into a text field, etc.
 
I appreciate any help I can get on this. Thanks!
 

D. Dane Williams
The Learning Center
Buckman Laboratories, International
901-272-6774 

 
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Help with listener for custom class (AS3)

2007-09-12 Thread Arul Prasad M L
From your cssLoaded and xmlLoaded methods, dispatch an event each,
announcing the completion of load.

eg

 public function xmlLoaded(event:Event):void {
  newXML = XML(event.target.data);
  dispatchEvent(new Event(xmlLoaded));
 }


And on the timeline, you can add a listener to that event by doing this:

var fileForThis:fileImports = new
fileImports(courseInfo.xml,styles.css);
fileForThis.addEventListener(xmlLoaded, onXMLLoad);

function onXMLLoad()
{
// xml loaded now
}

Of course thats not the best way to code ( you could create a custom event
object to pass more data etc, ) but the above should get you started.

Btw, your 'fileImports' class doesnt seem to be a UI class, so you dont have
to extend it from Sprite. Just extend EventDispatcher class.

~Arul Prasad.

On 9/12/07, Dane Williams [EMAIL PROTECTED] wrote:

 Greetings All,
 I'm trying to do more and more of my projects with external classes and,
 along with that, creating classes for routines that I regularly do. I have
 a
 class that reads an XML file and CSS file once it's called. It has worked
 fine for the first few projects I used it in. With my recent project, it's
 not wanted to behave. The code for the class is as follows:
 package {
 import flash.display.Sprite;
 import flash.text.StyleSheet;
 import flash.events.*;
 import flash.net.*;
 public class fileImports extends Sprite {
   public var newStyleSheet:StyleSheet = new StyleSheet();
   public var newXML:XML = new XML();
   public function fileImports(xmlFile:String, cssFile:String):void {
//load css file
var cssToLoad:URLRequest=new URLRequest(cssFile);
var cssLoader:URLLoader = new URLLoader;
cssLoader.load(cssToLoad);
//load xml file
var xmlToLoad:URLRequest=new URLRequest(xmlFile);
var xmlLoader:URLLoader = new URLLoader;;
xmlLoader.load(xmlToLoad);
//event listeners
xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);
cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
   }
   public function cssLoaded(event:Event):void {
newStyleSheet.parseCSS(event.target.data);
   }
   public function xmlLoaded(event:Event):void {
newXML = XML(event.target.data);
   }
 }
 }

 I am creating an instance on my main timeline with this:
 var fileForThis:fileImports = new
 fileImports(courseInfo.xml,styles.css);

 I am trying to use the data that is coming in with the XML file to
 populate
 some combo boxes. My problem is I don't know how to listen to the class
 from the main timeline to find out if the class is finished processing the
 XML. Right now if I try to use fileForThis.newXML I get a value of null.
 But if I put a trace on newXML in the class, it shows the content of my
 XML
 file.

 I have gotten this to work on other projects because I haven't tried to
 use
 the data immediately - so the data has time to process before it's put
 into a text field, etc.

 I appreciate any help I can get on this. Thanks!


 D. Dane Williams
 The Learning Center
 Buckman Laboratories, International
 901-272-6774


 ___
 Flashcoders@chattyfig.figleaf.com
 To change your subscription options or search the archive:
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 Brought to you by Fig Leaf Software
 Premier Authorized Adobe Consulting and Training
 http://www.figleaf.com
 http://training.figleaf.com




-- 
Arul Prasad
http://arulprasad.blogspot.com
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com