XML loads but cannot be used? Help Please.
Hi, I'm quite new to using XML but have followed some tutorials to get the data loaded and all seemed fine. But now the data is loaded (as i've traced it, it's definitely there) I can't seem to use it.
I'm building a a carousal which will display different projects i've made.
Here is my XML file
Actionscript Code:
<?xml version="1.0" encoding="UTF-8"?>
<site>
<!-- ALL PROJECTS -->
<!-- ============ -->
<projects>
<project>
<title>Campaign 1</title>
<image_path>projects/images/1.jpg</image_path>
<info>Brand 1</info>
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</content>
</project>
<project>
<title>Campaign 2</title>
<image_path>projects/images/2.jpg</image_path>
<info>Brand 2</info>
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</content>
</project>
<project>
<title>Campaign 3</title>
<image_path>projects/images/3.jpg</image_path>
<info>Brand 3</info>
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</content>
</project>
<project>
<title>Campaign 4</title>
<image_path>projects/images/4.jpg</image_path>
<info>Brand 4</info>
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</content>
</project>
<project>
<title>Campaign 5</title>
<image_path>projects/images/5.jpg</image_path>
<info>Brand 5</info>
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</content>
</project>
</projects>
</site>
Then in Flash I have an XML layer
Actionscript Code:
// XML LISTS //
// ========= //
var projectTitle:XMLList;
var projectImage:XMLList;
var projectInfo:XMLList;
var projectContent:XMLList;
// number of items
var projectsNum:Number;
// LOAD XML //
// ======== //
var xml:XMLLoader = new XMLLoader(this,"data.xml");
// function called when XML is loaded
function getXML(xmlData:XML):void {
// STORING RELEVANT DATA INTO LISTS FOR LATER ACCESS //
projectTitle = xmlData.projects.project.title;
projectImage = xmlData.projects.project.image_path;
projectInfo = xmlData.projects.project.info;
projectContent = xmlData.projects.project.content;
projectsNum = projectTitle.length();
trace(projectInfo);
}
And a projects layer
Actionscript Code:
import com.greensock.TweenLite;
import com.greensock.easing.Back;
// CONTAINER FOR SCROLLING
var panelContainer:Sprite = new Sprite;
addChild(panelContainer);
// ARRAY FOR REMOVING AND ADDING LISTENERS
var projectArray:Array = new Array( );
// ADDING ProjectPanel INSTANCES IN A LOOP
for(var i:Number=0;i<5; i++) {
var projectPanel:ProjectPanel = new ProjectPanel;
// positioning project panel instances
projectPanel.x = i*(projectPanel.width+10);
panelContainer.addChild(projectPanel);
// listen for click on panel
projectPanel.addEventListener(MouseEvent.CLICK, onClick);
}
function onClick(evt:MouseEvent):void{
dog.play();
catapult.play();
catapult_cat.play();
TweenLite.to(panelContainer, 0.5, {y:stage.stageHeight, ease:Back.easeIn});
addFullPanel();
removeListeners();
}
function removeListeners():void {
for (var i:Number=0; i<projectArray.length; i++) {
projectArray[i].removeEventListener(MouseEvent.CLICK, onClick);
}
}
function addListeners():void {
for (var i:Number=0; i<projectArray.length; i++) {
projectArray[i].addEventListener(MouseEvent.CLICK, onClick);
}
}
function slideUp():void {
TweenLite.to(panelContainer, 0.5, {y:stage.stageHeight/2, ease:Back.easeOut})
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
function onMove(evt:MouseEvent):void{
if(fullProjectPanelUp==false) {
TweenLite.to(panelContainer, 0.3, { x:-(stage.mouseX/980)*panelContainer.width+stage.stageWidth/1.4});
}
}
stop();
Up to this point everything works fine, the projects on the carousal are all the same at this point, no XML has been used.
But then I add in this code in my projects layer
Actionscript Code:
From this -
// ADDING ProjectPanel INSTANCES IN A LOOP
for(var i:Number=0;i<5; i++) {
var projectPanel:ProjectPanel = new ProjectPanel;
// positioning project panel instances
To this -
// ADDING ProjectPanel INSTANCES IN A LOOP
for(var i:Number=0;i<projectsNum; i++) {
var projectPanel:ProjectPanel = new ProjectPanel;
projectPanel.title.text = projectTitle[i];
projectPanel.info.text = projectInfo[i];
projectPanel.content.text = projectContent[i];
// positioning project panel instances
And now the carousal won't appear at all.
Any help please would be amazing, thank you!