I've built a slide show that loads content from an xml file, so far so good. However, the slide show needs to incorporate project buttons that will switch the content depending on which button is pressed i.e. when button 1 is press it needs to load 1.xml or when button 2 is pressed it should load 2.xml and so on.
I'm trying to keep everything in the first frame. Here's my current code:
var xmlFile:String="project1.xml";
// LOAD XML FOR THUMBNAILS
var urlRequest:URLRequest=new URLRequest(xmlFile);
var urlLoader:URLLoader = new URLLoader();
var myXML:XML = new XML();
var xmlList:XMLList;
myXML.ignoreWhitespace=true;
urlLoader.addEventListener(Event.COMPLETE,fileLoaded);
urlLoader.load(urlRequest);
var imageLoader = new Loader();
addChild(imageLoader);
var currentPosition:Number=0;
// XML NODE ARRAYS
var arraySlideNumber:Array = new Array();
var arraySlideTitle:Array = new Array();
var arraySlideCopy:Array = new Array();
var arraySlideImage:Array = new Array();
// POPULATE THUMBNAILS
function fileLoaded(e:Event):void {
myXML=XML(e.target.data);
xmlList=myXML.children();
for (var i:int=0; i<xmlList.length(); i++) {
//SET UP XML VARIABLES FOR CONTENT
var slideNumber:String=xmlList[i].slide_number;
var slideTitle:String=xmlList[i].title;
var slideCopy:String=xmlList[i].copy;
var slideImage:String=xmlList[i].image_location;
//PUSH CONTENT VARIABLES INTO ALLOCATED ARRAYS
arraySlideNumber.push(slideNumber);
arraySlideTitle.push(slideTitle);
arraySlideCopy.push(slideCopy);
arraySlideImage.push(slideImage);
//INITIALLY DRAW THE FIRST SLIDE
drawSlide();
//ACTIVATE BUTTONS
this.nextBtn.addEventListener(MouseEvent.MOUSE_DOWN, nextButtonclicked);
this.previousBtn.addEventListener(MouseEvent.MOUSE_DOWN, previousButtonclicked);
}
}
function drawSlide() {
//ADD TEXT CONTENT TO STAGE
this.slideNumber.text = (arraySlideNumber[currentPosition]);
this.slideTitle.text = (arraySlideTitle[currentPosition]);
this.slideCopy.text = (arraySlideCopy[currentPosition]);
//LOAD SLIDE IMAGE
var myRequest=new URLRequest(arraySlideImage[currentPosition]);
imageLoader.load(myRequest);
imageLoader.x=+1;
imageLoader.y=+21;
}
//CREATE BUTTON FUNCTIONS
function nextButtonclicked(e:Event):void {
if (currentPosition+1<arraySlideNumber.length) {
currentPosition=Math.min(currentPosition+1,arraySlideNumber.length-1+arraySlideTitle.length-1+arraySlideCopy.length-1+arraySlideImage.length-1);
drawSlide();
}
}
function previousButtonclicked(e:Event):void {
currentPosition=Math.max(0,currentPosition-1);
drawSlide();
}
//TAB FUNCTIONALITY
tab1.addEventListener(MouseEvent.MOUSE_DOWN, tab1Clicked);
function tab1Clicked(e:Event):void {
trace(xmlFile+urlRequest+xmlList);
xmlFile = "project1.xml";
urlLoader.load(urlRequest);
}
tab2.addEventListener(MouseEvent.MOUSE_DOWN, tab2Clicked);
function tab2Clicked(e:Event):void {
trace(xmlFile+xmlList);
xmlFile = "project2.xml";
urlLoader.load(urlRequest);
}
I'm trying the change the content of the xmlFile variable depending on which button is clicked but I can't figure out how to get the loader to recognise the new variables and trigger off the xml loader again to load in the new file.
Does this make sense?
If somebody could point me in the right direction, or even let me know whether I'm barking up the wrong tree it would be greatly appreciated! I'm just getting to grips with AS3 so apologies if the script isn't great.
Cheers,
Michelle

New Topic/Question
This topic is locked



MultiQuote


|