Jump to content
Search Community

DataLoader

chefkeifer test
Moderator Tag

Recommended Posts

I am currently trying to set up a news section using the DataLoader...i just learned the basics of the imageLoader the other day but need to get this one under my belt as well. just to give you an idea how i have it setup and need it set up. i have news article in a xml file and in flash i want to import those xml articles in succession down the page. i have made for loop to make that happen but i am confused on how to setup my xml file and the LoaderMax. i have a code snippet that i saw on a previous post and tried to use that but the way that one is set up it refers to a xml file with and url to a text file. I want to eliminate that txt file and have all my data in the xml file. does that make sense.

 

xml code now

<?xml version="1.0" encoding="iso-8859-1"?> 








 

 

here is my AS

import com.greensock.events.*;
import com.greensock.loading.*;
import com.greensock.*;
import flash.display.Sprite;
import flash.display.MovieClip;

LoaderMax.activate([DataLoader]);
//*****====================================================*****\\
var loader:XMLLoader = new XMLLoader("../xml/pitboard.xml", {name:"pitboards", onComplete:completeHandler});
//*****====================================================*****\\
function completeHandler(event:LoaderEvent):void {
	//trace("load complete. XML content: " + LoaderMax.getContent("pitboards"));
var myText:String = LoaderMax.getContent("headline");
	trace("Is this working: " + myText);
}
//*****====================================================*****\\
loader.load();
//*****====================================================*****\\
var newsContainer:Sprite = new Sprite;
newsContainer.x = 20;
newsContainer.y = 20;
addChild(newsContainer);
//*****====================================================*****\\
var newsArray:Array = new Array();
//*****====================================================*****\\
for(var k:Number=0;k<5;k++){
var newsItem:NewsItem = new NewsItem;
if(k>0){
      newsItem.y = k*(newsArray[k-1].height+10);
}
newsArray.push(newsItem);
newsContainer.addChild(newsItem);
}
//*****====================================================*****\\

Link to comment
Share on other sites

It sounds like you don't even need DataLoader - just use XMLLoader. For example, your XML could look like this:

 



This is the first headline
This is the first newsitem's article text.


This is the second headline
This is the second newsitem's article text.

 

And your ActionScript to load it in could look like this:

 

var loader:XMLLoader = new XMLLoader("../xml/pitboard.xml", {name:"pitboards", onComplete:completeHandler});
loader.load();

function completeHandler(event:LoaderEvent):void {
var xml:XML = event.target.content;
var xmlItems:XMLList = xml.newsitem;
for each (var xmlItem:XML in xmlItems) {
	trace("-------------");
	trace("headline: " + xmlItem.headline[0].text());
	trace("article: " + xmlItem.article[0].text());
}
}

 

I just traced the values out obviously, just to demonstrate the concept. You should be able to take them and plug them in wherever you want. The idea is simply to embed your headlines and articles right in the XML and parse them as you please.

 

Make sense?

 

By the way, if you want to learn more about how to work with XML in ActionScript, check out Senocular's great article at http://www.senocular.com/flash/tutorial ... page=4#e4x

Link to comment
Share on other sites

  • 2 weeks later...

I have done the follwing and i cant seem to get it to work. once again i just cant get my head around it. it seems so easy sometimes but then i just cant see the big picture..

 

i am just trying to pull data from an xml file and have it loop within a movieclip and dynamic text boxes...hell, i dont know if i am even explaining myself the right way...thanks for all your help

 

i have attached an fla file...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...