How to return Loader object as Class
I have to implement a menu with icons using actionscript only. I create a data provider from XML and set
menu = Menu.createMenu(null, dataArray, true)开发者_如何学JAVA;
menu.iconFunction = iconFunction;
Till here everything is fine and my menu is presented, but only with labels.
I create iconFunction
as following:
private function iconFunction(item:Object):Class
{
var st:Loader = new Loader();
st.load(new URLRequest(item.icon));
return ?;
}
and here's my question: how do I return my loader object as Class
?
I'm googling this for hours and cannot find something relevant.
Thanks a lot!
You can use Ben Stucki's solution as a base.
Will this example help?
package {
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLLoaderDataFormat;
import flash.geom.Rectangle;
import flash.events.Event;
public class Main extends Sprite {
private var urlLoader:URLLoader = new URLLoader();
public function Main() {
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load(new URLRequest("http://server.com/image.jpg"));
urlLoader.addEventListener(Event.COMPLETE, completeHandler);
}
private function completeHandler(event:Event):void {
var loader:Loader = new Loader();
loader.loadBytes(urlLoader.data);
addChild(loader);
}
}
}
精彩评论