Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Acessing an URLLoader's "parent"

Status
Not open for further replies.

maguskrool

Technical User
Dec 11, 2006
77
PT
And hello again...

I created a custom class called MyFile.as (see attached code), representing a css or xml file to be loaded. The purpose of this class is to gather several properties relating to a file, so they can be used by several .swfs that will be loaded later.

I create an instance of MyFile, load some content with an URLLoader (uld) and listen for the load to complete. How can I then reference the MyFile instance to which the URLLoader belongs?

Thank you.

Code:
//MyFile.as
//I'm not including the package and import stuff.

public class MyFile {
   private var _urlLoader:URLLoader;
   private var _special:String;
   //getter and setter for _urlLoader: uld; _special: spl;

   public function MyFile($special:String):void {
      _special = $special;
   }
}

//.fla
var myOne:MyFile = new MyFile("blah one");
myOne.uld = new URLLoader(new URLRequest("one.xml");
myOne.uld.addEventListener(Event.COMPLETE, handleAll);
//same for myTwo,...,myN.


function handleAll(evt:Event):void {
   //Should on act on the myN.spl property.
}

 
MyFile.as
Code:
package {
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class MyFile extends URLLoader {
		public var spl:String;
		//use getter and setter if you like

		public function MyFile($req:URLRequest, $special:String):void {
			super($req);
			spl = $special;
		}
	}
}
FLA
Code:
var myOne:MyFile = new MyFile(new URLRequest("one.xml"), "blah one");
myOne.addEventListener(Event.COMPLETE, handleAll);
//same for myTwo,...,myN.

function handleAll(evt:Event):void {
	//Should on act on the myN.spl property.
	trace(evt.target.spl);
}
Output
[tt]blah one[/tt]

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top