如何使用actionscript(flash)用xml驱动的图库中的数字替换图像缩略图
我使用 Actionscript 3.0 设计了一个 xml 驱动的相册。
首先,当 swf 文件运行时,所有缩略图都会加载,然后我下面有缩略图,当我单击它们时,大图像会加载。
我希望将缩略图替换为从 xml 文件动态形成的数字。即我只想要数字,单击它们会加载相应的图像
请给出解决方案,或者请建议一个好的教程。非常感谢:)
这是我编写的代码,但我一直在替换
var titleArray:Array = new Array();
var descriptionArray:Array = new Array();
var largeImageArray:Array = new Array();
var thumbnailArray:Array = new Array();
//XML
var imageNum:Number=0;
var totalImages:Number;
//Load in XML
var XMLURLLoader:URLLoader = new URLLoader();
XMLURLLoader.load(new URLRequest("portfolio.xml"));
XMLURLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(event:Event):void {
var theXMLData:XML=new XML(XMLURLLoader.data);
totalImages=theXMLData.title.length();
for (var i:Number=0; i< theXMLData.title.length(); i++) {
titleArray.push(theXMLData.title[i]);
descriptionArray.push(theXMLData.description[i]);
largeImageArray.push(theXMLData.largeImage[i]);
thumbnailArray.push(theXMLData.thumbImage[i]);
}
loadThumbnail();
}
myScrollPane.source=allThumbnails;
//Load the thumbnails
function loadThumbnail():void {
trace(imageNum);
var thumbLoader1:Loader = new Loader();
thumbLoader1.load(new URLRequest(thumbnailArray[imageNum]));
thumbLoader1.x=100*imageNum; //Distance between images
//stores the appropriate info for the thumbnail
var thisLargeImage:String=largeImageArray[imageNum];
var thisTitle:String = titleArray[imageNum];
var thisDescription:String = descriptionArray[imageNum];
thumbLoader1.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded1);
function thumbLoaded1(event:Event):void {
//add the thumbnail to the allThumbnails instance
allThumbnails.addChild(thumbLoader1);
myScrollPane.update();
allThumbnails.buttonMode=true;
thumbLoader1.addEventListener(MouseEvent.CLICK,loadMainImage1);
function loadMainImage1(event:MouseEvent):void {
largeUILoader.source=thisLargeImage;
selectedTitle.text=thisTitle;
selectedDesc.htmlText=thisDescription;
}
}
imageNum++;
if (imageNum<totalImages) {
loadThumbnail();
}
}
i've designed an xml driven photogallery using actionscript 3.0.
First when the swf file is run, all the thumbnails load in, Then I have thumbnails below, when i click them the large image loads in.
I wanted the thumbnails to be replaced with the numbers which form dynamically from the xml file. i.e I simply want the numbers, on clicking them loads respective images
Please give a solution to this, or please suggest a good tutorial. Thanks very much :)
here's the code i've worked on and im stuck replacing
var titleArray:Array = new Array();
var descriptionArray:Array = new Array();
var largeImageArray:Array = new Array();
var thumbnailArray:Array = new Array();
//XML
var imageNum:Number=0;
var totalImages:Number;
//Load in XML
var XMLURLLoader:URLLoader = new URLLoader();
XMLURLLoader.load(new URLRequest("portfolio.xml"));
XMLURLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(event:Event):void {
var theXMLData:XML=new XML(XMLURLLoader.data);
totalImages=theXMLData.title.length();
for (var i:Number=0; i< theXMLData.title.length(); i++) {
titleArray.push(theXMLData.title[i]);
descriptionArray.push(theXMLData.description[i]);
largeImageArray.push(theXMLData.largeImage[i]);
thumbnailArray.push(theXMLData.thumbImage[i]);
}
loadThumbnail();
}
myScrollPane.source=allThumbnails;
//Load the thumbnails
function loadThumbnail():void {
trace(imageNum);
var thumbLoader1:Loader = new Loader();
thumbLoader1.load(new URLRequest(thumbnailArray[imageNum]));
thumbLoader1.x=100*imageNum; //Distance between images
//stores the appropriate info for the thumbnail
var thisLargeImage:String=largeImageArray[imageNum];
var thisTitle:String = titleArray[imageNum];
var thisDescription:String = descriptionArray[imageNum];
thumbLoader1.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded1);
function thumbLoaded1(event:Event):void {
//add the thumbnail to the allThumbnails instance
allThumbnails.addChild(thumbLoader1);
myScrollPane.update();
allThumbnails.buttonMode=true;
thumbLoader1.addEventListener(MouseEvent.CLICK,loadMainImage1);
function loadMainImage1(event:MouseEvent):void {
largeUILoader.source=thisLargeImage;
selectedTitle.text=thisTitle;
selectedDesc.htmlText=thisDescription;
}
}
imageNum++;
if (imageNum<totalImages) {
loadThumbnail();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需添加缩略图,只需添加文本字段并将相应的数字分配给其文本属性即可。
使用文本字段名称属性来存储较大的图像 URL。
Instead of adding thumbnails, simply add TextFields and assign respective number to their text property.
Use the Textfield name property to store the larger Image url.