使用自定义LoaderInfo类自定义的AS3 Loader类? [英] custom AS3 Loader class that uses a custom LoaderInfo class?
问题描述
这是一个问题,特别是有关创建自定义类加载器作为后续到<一个href="http://stackoverflow.com/questions/758322/how-do-i-modify-existing-as3-events-so-that-i-can-pass-data">http://stackoverflow.com/questions/758322/how-do-i-modify-existing-as3-events-so-that-i-can-pass-data.如果这不是正确的方式去了解这一点,让我知道。
This is a question specifically about creating a custom Loader class as a followup to http://stackoverflow.com/questions/758322/how-do-i-modify-existing-as3-events-so-that-i-can-pass-data. If this wasn't the right way to go about this, let me know.
我有一个自定义类加载器和一个自定义LoaderInfo类。我想不通的是如何让Loader类使用自定义LoaderInfo类,因为它的contentLoaderInfo属性。
I have a custom Loader class and a custom LoaderInfo class. What I can't figure out is how to have the Loader class use the custom LoaderInfo class as it's contentLoaderInfo property.
package com.display {
import flash.display.Loader;
import com.display.CustomLoaderInfo;
public class CustomLoader extends Loader {
public var customData:*;
public function CustomLoader(passedData: *= null) {
customData = passedData;
}
}
}
^要做的东西在里面,使之具有新的CustomLoaderInfo
^ Have to do something in there to make it have the new CustomLoaderInfo
package com.display {
import flash.display.LoaderInfo;
import flash.events.Event;
import com.events.CustomEvent;
public class CustomLoaderInfo extends LoaderInfo {
public var customData:*;
public function CustomLoaderInfo(passedData: *= null) {
customData = passedData;
}
override public function dispatchEvent(event:Event):Boolean {
var customEvent:CustomEvent = new CustomEvent(event.type, customData, event.bubbles, event.cancelable);
return super.dispatchEvent(customEvent);
}
}
}
^可能的工作,但因为我不能让CustomLoader使用它,我还不知道。
^ That might work, but since I can't get CustomLoader to use it, I don't know yet.
推荐答案
我不知道它是如何融入你在做什么,但你不能懒得做一个扩展的LoaderInfo的。 Loader.contentLoaderInfo有一个属性称为装载器将返回装载程序(或在这种情况CustomLoader)用于那个。理论上你可以做到这一点与你有CustomLoader类:
I don't know how it fits into what you're doing, but you could not bother making an extended LoaderInfo at all. Loader.contentLoaderInfo has a property called loader that will return the Loader (or in this case CustomLoader) that was used. In theory you can just do this with the CustomLoader class that you have:
var loader: CustomLoader = new CustomLoader("Extra Data");
loader.load(new URLRequest("file.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
function loaderComplete(event: Event) : void
{
var customData:* = (event.target.loader as CustomLoader).customData;
trace(customData); // Extra Data
}
这篇关于使用自定义LoaderInfo类自定义的AS3 Loader类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!