Click to See Complete Forum and Search --> : Extending Loader
joshstrike
09-06-2007, 05:59 PM
Hey...
I really want to be able to pass data via a Loader.contentLoaderInfo COMPLETED event. Since the event.target upon receipt seems not to have access to the Loader, what I want to do is something like...
class DLoader extends Loader {
function DLoader() {
super();
}
override function ***? {
//create a dynamic version of the contentInfoLoader here//
contentLoaderInfo=new DLoaderInfo(_request);//again, not sure how this should be structured//
}
}
dynamic class DLoaderInfo extends LoaderInfo {
function DLoaderInfo(request?) {
super(request);
}
}
Can anyone help me fill in the blanks...?
cancerinform
09-06-2007, 06:44 PM
I don't know but are you looking for something like this?
http://flashas3.flashscript.biz/Loaderclass/LoaderClass_4.html
joshstrike
09-06-2007, 07:01 PM
Thanks -- that might kinda work but it seems really inelegant and wasteful to have MovieClips with holders just so I can get a name passed through the contentInfoLoader event...
I'm just trying to figure out how to extend Loader so it will run a dynamic extension of LoaderInfo as its contentInfoLoader, so I can do this:
var req:URLRequest;
for (var i:Number = 0;i<10;i++) {
req = new URLRequest("url.html");
loaders.push(new Loader());
loaders[i].contentLoaderInfo.name = String(i); //THIS is what I can't do//
loaders[i].contentLoaderInfo.addEventListener(Event.COMPLETE D,gotLoaded,false,0,true);
loaders[i].load(req);
}
function gotLoaded(evt:Event) {
trace (evt.target.name);
//I just need to know which loader triggered the event so I can fade it up.//
}
cancerinform
09-07-2007, 05:22 AM
In that example you can set the MovieClip to null and work only with the loader content:
var url:String = "Animation.swf";
var lc:LoaderClass = new LoaderClass ();
lc.initLoader (url, loadFinished, null);
function loadFinished (event:Event):void
{
var loadedName:Sprite = event.target.content;
this.addChild(loadedName);
}
joshstrike
09-07-2007, 12:46 PM
Fine, but that still doesn't give me the name of the loader from the event, does it? I mean unless I make the loader dispatch an event to the LoaderClass and then the LoaderClass be dynamic and dispatch...that just seems crazy to try and do such a simple thing; maybe I'm asking the wrong question: If I get the contentInfoLoader as the target of an event, how do I access the Loader it's part of? The Loader is not its .parent. All I need is to know which loader I'm using, and I can name the loader, but I can't name the contentInfoLoader, 'cause it isn't dynamic and there's no .name property.
So that's all I need to know...how do I access the Loader from the contentInfoLoader that should just be a child of it?
cancerinform
09-07-2007, 01:30 PM
You can give the Loader a name
loaders1.name = "loader1";
then you should be able to get the name by using
event.target.name;
You cannot name the contentLoaderInfo.
I have not tried it but it should work.
joshstrike
09-07-2007, 02:40 PM
...but the listener needs to go on the loader.contentLoaderInfo, not on the loader itself.
So event.target is the contentLoaderInfo, and it can't be named. event.target.name throws an error.
And event.target.parent throws an error.
So from that event, how do I reference the loader...is the question...
joshstrike
09-07-2007, 03:36 PM
okay...I solved it, here's how, but I don't know why this works; I'm surprised I'm only picking up one event from outside, and it's the one I wanted that's getting dispatched by my dispatch function; I kind of thought I was going to get that event AND the event dispatched automatically by the Loader class, but I'm not. Anyone know why? Anyone know where I can find a copy of the actual Loader class so I can see what's going on under the hood there?
package components {
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.events.ProgressEvent;
public class ProxyLoader extends Loader {
public var data:Object = new Object();
function ProxyLoader() {
super();
}
public function proxyLoad(req:URLRequest):void {
contentLoaderInfo.addEventListener(Event.COMPLETE, this.dispatch,false,0,true);
contentLoaderInfo.addEventListener(ProgressEvent.P ROGRESS,this.dispatch,false,0,true);
contentLoaderInfo.addEventListener(Event.INIT,this .dispatch,false,0,true);
load(req);
}
private function dispatch(evt:*) {
this.dispatchEvent(evt);
}
}
}
Cheers,
Josh
flashkit.com
Copyright Internet.com Inc., All Rights Reserved.