用flash调用xml文件里的图片,每个图片都带有链接,代码怎么写

2025-01-05 03:14:25
推荐回答(2个)
回答1:

假设xml格式




//图片容器
public class PicClass extends Sprite{
private var link_url:String;
private var pic_url:String;
private var loader:Loader;
public function PicClass(){
loader = new Loader();
addChild(loader);
}

public function init(xml:XML):void{
this. pic_url = xml.@url;
this.link_ulr = xml.@linkurl;
loader.load(this.pic_url);
}
}
//主类
public class Main extends Sprite{
public function Main():void{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoadedxml);
loader.load(new URLRequest("xml地址"));
}
private function onLoadedxml(evt:Event):void{
var xml:XML = new XML(evt.target.data);
for(var i:int = 0;i < xml.pic.length();i ++){
var pic:PicClass = new PicClass();
pic.init(xml.pic[i]);

pic.x = i*(pic.width + 10);
addChild(pic);
}
}
}
简略介绍:通过主类加载xml,通过xml创建图片,并通过图片容器类初始化内容

回答2:

onClick事件吧..