stop();
//var url:Array=new Array(”1.jpg”,”2.jpg”,”3.jpg”)
var i:Number =0;
loadmovie();
//————-按钮事件——————–
btn.addEventListener(MouseEvent.CLICK,loadnext);
function loadnext(event:MouseEvent) {
i++;
loadmovie();
}
//—————读取图片—————-
function loadmovie() {
var container:Sprite = new Sprite();//建立容器
addChild(container);//把容器加入舞台
var pictLdr:Loader = new Loader();//建立loader对象
var pictURL:String = url[i];//载入文件名称
var pictURLReq:URLRequest = new URLRequest(pictURL);//建立载入接收对象
pictLdr.load(pictURLReq);//载入
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);//载入完成后响应
pictLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imgLoading);
pictLdr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imgerror);
function imgLoaded(event:Event):void {
//loading_txt.visible=false;
container.addChild(pictLdr.content);//把载入的对象加入容器
container.x=50;//载入后控制
container.y=50;
container.width=200;
container.height=150;
}
function imgLoading(event:ProgressEvent):void {
loading_txt.text = “图片已加载”+Math.round ((event.bytesLoaded/event.bytesLoaded)*100)+”%”;
}
function imgerror(event:IOErrorEvent):void {
trace(”图片不存在”);
}
}
pic/001.jpg
spic/001.jpg
pic/002.jpg
spic/003.jpg
读取XML的代码:
stop();
var pictotal:Number;
var url:Array=new Array;
var surl:Array=new Array;
var myXML:XML = new XML();
var XML_URL:String = “list.xml”;
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
myLoader.addEventListener(ProgressEvent.PROGRESS, xmlLoading);
myLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlError);
function xmlLoaded(event:Event) {
var myXML:XML = XML(myLoader.data);
pictotal=myXML.img.length();
for (i=0; i
url[i]=myXML.img[i].url;
surl[i]=myXML.img[i].surl;
}
play();
}
function xmlLoading(event:ProgressEvent) {
loading_txt.text = “XML已加载”+Math.round ((event.bytesLoaded/event.bytesLoaded)*100)+”%”;
}
function xmlError(event:IOErrorEvent) {
trace(”XML加载失败”);
}
//var url:Array=new Array(”1.jpg”,”2.jpg”,”3.jpg”)
var i:Number =0;
loadmovie();
//————-按钮事件——————–
btn.addEventListener(MouseEvent.CLICK,loadnext);
function loadnext(event:MouseEvent) {
i++;
loadmovie();
}
//—————读取图片—————-
function loadmovie() {
var container:Sprite = new Sprite();//建立容器
addChild(container);//把容器加入舞台
var pictLdr:Loader = new Loader();//建立loader对象
var pictURL:String = url[i];//载入文件名称
var pictURLReq:URLRequest = new URLRequest(pictURL);//建立载入接收对象
pictLdr.load(pictURLReq);//载入
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);//载入完成后响应
pictLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imgLoading);
pictLdr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imgerror);
function imgLoaded(event:Event):void {
//loading_txt.visible=false;
container.addChild(pictLdr.content);//把载入的对象加入容器
container.x=50;//载入后控制
container.y=50;
container.width=200;
container.height=150;
}
function imgLoading(event:ProgressEvent):void {
loading_txt.text = “图片已加载”+Math.round ((event.bytesLoaded/event.bytesLoaded)*100)+”%”;
}
function imgerror(event:IOErrorEvent):void {
trace(”图片不存在”);
}
}
读取XML的代码:
stop();
var pictotal:Number;
var url:Array=new Array;
var surl:Array=new Array;
var myXML:XML = new XML();
var XML_URL:String = “list.xml”;
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
myLoader.addEventListener(ProgressEvent.PROGRESS, xmlLoading);
myLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlError);
function xmlLoaded(event:Event) {
var myXML:XML = XML(myLoader.data);
pictotal=myXML.img.length();
for (i=0; i
url[i]=myXML.img[i].url;
surl[i]=myXML.img[i].surl;
}
play();
}
function xmlLoading(event:ProgressEvent) {
loading_txt.text = “XML已加载”+Math.round ((event.bytesLoaded/event.bytesLoaded)*100)+”%”;
}
function xmlError(event:IOErrorEvent) {
trace(”XML加载失败”);
}
沒有留言:
張貼留言