Skip to main content
Inspiring
October 29, 2012
Question

Please I need a Little Help with xmlloader

  • October 29, 2012
  • 1 reply
  • 6615 views

Hello pretty people,

Could someone help me with this code?

I have an xmlloader Class, which load an xml file.

This is the code...when I trace the xml, it load with any problem but when

I want that load it, nothing happen, and there is no throw an error too.

Would you please tell me why nothin happen? I am using the main time.

Thanks in advance for some help.

Regards

Joselyn

import flash.events.Event;
import com.greensock.TweenLite;
import com.greensock.easing.Back;


// XML LISTS //
// ========= //

var projectTitle:XMLList;
var projectImage:XMLList;
var projectInfo:XMLList;
var projectContent:XMLList;
var projectClient:XMLList;
var projectMedia:XMLList;
var projectTechnology:XMLList;
var projectLink:XMLList;

var newsTitle:XMLList;
var newsInfo:XMLList;
var newsContent:XMLList;

var newsTitleArray:Array;
var newsInfoArray:Array;
var newsContentArray:Array;

// number of items
var projectsNum:Number;
var newsNum: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;
projectClient = xmlData.projects.project.client;
projectMedia = xmlData.projects.project.media;
projectTechnology = xmlData.projects.project.technology;
projectLink = xmlData.projects.project.link;

newsTitle = xmlData.news.article.title;
newsInfo = xmlData.news.article.info;
newsContent = xmlData.news.article.content;

projectsNum = projectTitle.length();
newsNum = newsTitle.length();
trace(projectInfo);

newsTitleArray = xmlData.news.article.title.text().toXMLString().split("\n") ;
newsTitleArray.reverse();

newsInfoArray = xmlData.news.article.info.text().toXMLString().split("\n") ;
newsInfoArray.reverse();

newsContentArray = xmlData.news.article.content.text().toXMLString().split("\n") ;
newsContentArray.reverse();


}

//this is one part of the complete cody

//CONTAINER FOR SCROLLING

var panelContainer:Sprite = new Sprite();
addChild(panelContainer);

//ARRAY FOR REMOVING AND ADDING LISTENERS

var panelArray:Array = new Array();

var MT:MovieClip = new MovieClip(); //before I declare this variable to load the xml, was the problem//


//ADDING PROJECTPANEL IN A LOOP
for (var i:Number=0; i<MT.projectsNum; i++){

    var projectPanel:ProjectPanel = new ProjectPanel();


    //INSERT XML CONTENT
    projectPanel.title.text = MT.projectTitle;
    projectPanel.info.text = MT.projectInfo;
    projectPanel.content.text = MT.projectContent.substr(0,150)+"...Ver mas";

    projectPanel.loadImage(MT.projectImage);

    projectPanel.x = i*(projectPanel.width+5);
    panelContainer.addChild(projectPanel);
    panelArray.push(projectPanel);
    //listener for click on ProjectPanel
    projectPanel.addEventListener(MouseEvent.CLICK, onClick); 
}

function onClick(evt:MouseEvent):void{

for(var i:Number = 0; i<MT.projectsNum; i++){
  panelContainer.removeEventListener(MouseEvent.CLICK, onClick);
}

removeChild(panelContainer);
TweenLite.to(panelContainer, 0.5, {y:stage.stageHeight, ease:Back.easeIn});
this.addFullPanel();

removeListeners();

}

function removeListeners():void{

for(var i:Number = 0; i<MT.projectsNum; i++) {
 
  panelContainer.removeEventListener(MouseEvent.CLICK, onClick);
}
}

function addListeners():void{

for(var i:Number = 0; i<MT.projectsNum; i++) {
 
  panelContainer.addEventListener(MouseEvent.CLICK, onClick);
}
}

function slideUp():void{

TweenLite.to(panelContainer, 0.5, {y:0, ease:Back.easeOut});
}

stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);

function onMove(evt:MouseEvent):void {
//trace(mouseX);
if(fullProjectPanelUp==false){
 
  TweenLite.to(panelContainer, 0.3, { x:-(stage.mouseX/800)*panelContainer.width+stage.stageWidth/2});
  //tweenPanelContainer = new Tween(panelContainer, "alpha", Strong.easeOut, 0, 1, 3, true);
}
}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
October 29, 2012

when that code executes, does data.xml load?  if yes, what's the problem?

Joselyn6Author
Inspiring
October 29, 2012

Hi, Kglad, Thanks a lot for your answer.

The problem is that when I declare in the code "trace(data.xml)", it appear in the output, but the stage is empty.

Regards.

Joselyn

kglad
Community Expert
Community Expert
October 30, 2012

you need to wait until getXML() is called before trying to use any of the xml data.