如何使用actionscript(flash)用xml驱动的图库中的数字替换图像缩略图

发布于 2024-12-18 03:46:10 字数 2122 浏览 3 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘你却要生生世世 2024-12-25 03:46:10

无需添加缩略图,只需添加文本字段并将相应的数字分配给其文本属性即可。

使用文本字段名称属性来存储较大的图像 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文