Jump to content
Search Community

XMLList & nodes

ShortBus test
Moderator Tag

Recommended Posts

Hi All-

 

If I'm setting up, say an XML slideshow using XML data like:

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







 

And AS3/GS code:

import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.ContentDisplay;
import com.greensock.loading.SWFLoader;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.XMLLoader;
import com.greensock.TweenLite;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;

LoaderMax.activate([sWFLoader]);

var mainHolder:MovieClip;
var xmlQueue:LoaderMax;
var xmlArray:Array;
var xmlTotal:Number;
var xmlContent:String;

btn1.addEventListener(MouseEvent.CLICK, goToMov1);
btn2.addEventListener(MouseEvent.CLICK, goToMov2);
btn3.addEventListener(MouseEvent.CLICK, goToMov3);
btn4.addEventListener(MouseEvent.CLICK, goToMov4);

// Preloader stuff
var txtProgress:TextField = new TextField();
txtProgress.autoSize = TextFieldAutoSize.CENTER;
txtProgress.x = 187.5;
txtProgress.y = 190;
txtProgress.selectable = false;
var txtProgressFormat:TextFormat = new TextFormat();
txtProgressFormat.color = 0x888888;
txtProgressFormat.size = 18;
plWheel.visible = false;

function progressHandler(event:LoaderEvent):void {
plWheel.visible = true;
addChild(txtProgress);
var perc:Number = xmlLoader.progress;
txtProgress.text = Math.ceil(perc*100).toString() + "%";
txtProgress.setTextFormat(txtProgressFormat);
}

var xmlLoader:XMLLoader=new XMLLoader("assets/data.xml",{name:"assetList", estimatedBytes:15000000, onComplete:xmlHandler, onProgress:progressHandler});
xmlLoader.load();

function xmlHandler(event:LoaderEvent):void {
trace("XML Loaded!");
//Hide the preloader components
txtProgress.visible = false;
plWheel.visible = false;
//Process the XML
var xmlQueue = LoaderMax.getLoader("xmlQueue");
var xmlArray = xmlQueue.content;
   for (var i:int = 0; i < xmlArray.length; i++) {
       mainHolder.addChild(xmlArray[0]);
	xmlArray[0].scaleX = xmlArray[0].scaleY = 0.25; 
       TweenLite.to(xmlArray[0], 1, {alpha:1});
   }
xmlTotal = xmlArray.length;
xmlContent = event.target.content;
//setupThumbs();
trace(xmlArray.length + " items stored in xmlArray");
trace(event.target);
trace("Number of children in thumbHolder now is " + thumbHolder.numChildren);
trace("Number of children in mainHolder now is " + mainHolder.numChildren);
}

 

How do I identify "XMLList" nodes to associate thumbs with display? I almost want to say images but I'm using SWF files for thumbs and images (lighter project). I can't even figureout how to trace & get the node values, just the entire xml contents.

Feeling quite lost of is it better in this scenario to call teh loaders from script?

Thanks

Karl

Link to comment
Share on other sites

How do I identify "XMLList" nodes to associate thumbs with display?

I don't know exactly what that means.

 

----

 

I can't even figureout how to trace & get the node values, just the entire xml contents.

 

if you want to manually parse the xml data you can do this:

 

 

function xmlHandler(event:LoaderEvent):void {
  trace("XML Loaded!");
  var xml:XML = event.target.content
var mySWFLoaderNodes:XMLList = xml..SWFLoader;

//loop through each  node and get the THUMb attribute	

for each(var n in mySWFLoaderNodes){
	trace(n.@THUMB);
	}

}

 

there are ways of going through LoaderMax to get access to the child loaders... using getChildren(), getLoader() getChildAt() etc. Once you have targeted a particular loader you can get anything out of its vars such as

 

var someLoader:SWFLoader = LoaderMax.getLoader("movie1");

trace(someLoader.vars.THUMB)

 

From the XMLLoader documentation: http://www.greensock.com/as/docs/tween/ ... oader.html

 

You may put extra data in the LoaderMax-related nodes that you'd like associated with that particular loader. XMLLoader will put all of the attributes from the XML node into the vars object of the resulting loader as well as an extra rawXML property which will contain the raw XML for that node. For example, if this node is in your XML document:

...

 

...

 

Notice the "description" attribute which isn't a LoaderMax-specific property. XMLLoader will still put that value into the VideoLoader's vars property and create a rawXML property there that contains the whole XML node (including the children) so that you can easily get whatever data you need like this:

 

function completeHandler(event:LoaderEvent):void {

var video:VideoLoader = LoaderMax.getLoader("video1");

var description:String = video.vars.description;

var xml:XML = video.vars.rawXML;

trace("first link url: " + xml.links[0].link[0].@url); //traces "first link url: http://www.greensock.com"

}

Link to comment
Share on other sites

Hi Carl-

 

I am using Jack's slideshow demo as reference for my project but setting up xml differently (as noted) and combining it in the fla. That's where I got stumped. Between the 2 classes of the demo I couldn't figure out how to target the thumbs for clicking & displaying the associated image.

I'm jumping back into it this morning, armed with your troubleshooting info you provided & see if I get smarter ;)

Thanks

K

Link to comment
Share on other sites

I guess, more to the point, I'm asking if there's a way to reference the "THUMB" var in the queue that's already created. "url" was easy because it's native(?) and the nodes are setup as ContentDisplay objects. I can't really use SWFLoader.@THUMB for a reference and I've tried to restructure the xml this but it got cranky :




Would I need to manually parse the XML & define the "THUMB" url as ContentDisplay objects in a separate function & loader?

I'm just digging to see how much loader info can be stashed in XML and used correctly in a gallery/slideshow scenario. Just a learning newb :D

 

Thanks

K

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...