views:

1011

answers:

2

Here is my entire Script as I can't seem to figure out where the problem is.

The symptoms are that where I addChild(book) , is not the appropriate place for this to be added properly and sequentially with the thumbs as well. As a result, and to my surprise, the only way I can get these to appear so far is by writing a faulty trace statement which somehow pops them up in the top left corner. Any suggestions would be greatly appreciated! Thank you!!

var rowsW:Number;
var my_xW:Number;
var my_yW:Number;
var my_thumb_widthW:Number;
var my_thumb_heightW:Number;
var my_imagesW:XMLList;
var my_totalW:Number;

var container_mcW:MovieClip;
var preloaders_mcW:MovieClip;
var book:TextField = new TextField();
var author:TextField = new TextField();
var publisher:TextField = new TextField();
book.selectable = true;

var x_counterW:Number = 0;
var y_counterW:Number = 0;

var my_tweensW:Array = [];
var container_mc_tweenW:Tween;

var myXMLLoaderW:URLLoader = new URLLoader();

myXMLLoaderW.load(new URLRequest("WORKS.xml"));
myXMLLoaderW.addEventListener(Event.COMPLETE, processXMLW);

createContainerW();
callThumbsW();

function processXMLW(e:Event):void {
var myXMLW:XML = new XML(e.target.data);

rowsW = myXMLW.@ROWS;
my_xW = myXMLW.@XPOSITION;
my_yW = myXMLW.@YPOSITION;
my_thumb_widthW = myXMLW.@WIDTH;
my_thumb_heightW = myXMLW.@HEIGHT;
my_imagesW = myXMLW.IMAGE;
my_totalW = my_imagesW.length();

myXMLLoaderW.removeEventListener(Event.COMPLETE, processXMLW);
myXMLLoaderW = null;

}

function createContainerW():void {
container_mcW = new MovieClip();
container_mcW.x = my_xW;
container_mcW.y = my_yW;
addChild(container_mcW);


preloaders_mcW = new MovieClip();
preloaders_mcW.x = container_mcW.x;
preloaders_mcW.y = container_mcW.y;
addChild(preloaders_mcW);
}

function callThumbsW():void {
for (var i:Number = 0; i < my_totalW; i++) {

 var thumb_urlW = my_imagesW[i].@THUMB;
 book.text = my_imagesW[i].@TITLE;
 author.text = my_imagesW[i].@AUTHOR;
 publisher.text = my_imagesW[i].@PUBLISHER;

 var thumb_loaderW = new Loader();
 thumb_loaderW.load(new URLRequest(thumb_urlW));

thumb_loaderW.contentLoaderInfo.addEventListener(Event.COMPLETE,thumbLoadedW);

 thumb_loaderW.name = i;

 book.x = (40)*x_counterW;
 book.y = (my_thumb_heightW+40)*y_counterW;
 thumb_loaderW.x = (my_thumb_widthW+10)*x_counterW;
 thumb_loaderW.y = (my_thumb_heightW+10)*y_counterW;


 container_mcW.addChild(book);
 container_mcW.addChild(author);
 container_mcW.addChild(publisher);
 trace("my x equals" (book.x));

 if (y_counterW+1 < rowsW) {
  y_counterW++;
 } else {
  y_counterW = 0;
  x_counterW++;
 }
 var preloader_pbW:ProgressBar = new ProgressBar();
 preloader_pbW.source = thumb_loaderW.contentLoaderInfo;
 preloader_pbW.x = thumb_loaderW.x;
 preloader_pbW.y = thumb_loaderW.y;
 preloader_pbW.width = my_thumb_widthW;
 preloader_pbW.height = my_thumb_heightW;
 preloaders_mcW.addChild(preloader_pbW);

 preloader_pbW.addEventListener(Event.COMPLETE, donePbW);

}
}

function thumbLoadedW(e:Event):void {
var my_thumbW:Loader = Loader(e.target.loader);
container_mcW.addChild(my_thumbW);

my_tweensW[Number(my_thumbW.name)]=new Tween(my_thumbW, "alpha", Strong.easeIn, 0,1,0.5, true);

my_thumbW.contentLoaderInfo.removeEventListener(Event.COMPLETE, thumbLoadedW);
}

function donePbW(e:Event):void {
var my_pbW:ProgressBar = ProgressBar(e.target);
preloaders_mcW.removeChild(my_pbW);
my_pbW.removeEventListener(Event.COMPLETE, donePbW);
}
+1  A: 

It doesn't seem to me that you're loading your XML properly. You should be using a URLLoader, not a loader to load the XML. You'll then need to wait til Event.COMPLETE is trigged to parse the data and add your text fields.

From sephiroth (http://www.sephiroth.it/tutorials/flashPHP/E4X/):

import flash.net.URLLoader
import flash.net.URLRequest
import flash.xml.XML
import flash.event.*
import flash.error.*

var mainXML:XML;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("http://www.sephiroth.it/tutorials/flashPHP/E4X/files/test.xml"));


function onComplete(evt:Event)
{
    mainXML = new XML(loader.data)
    trace("xml loaded, start parsing using E4X syntax");
}

Well, now that you've massively edited your question, yes, it's obvious you already have that in there. I'd try tracing/watching loader.data before you try to parse it into an xml object to see exactly what data you're trying to parse into XML. It sounds like you're maybe getting some data you're not expecting.

quoo
Hmm..I already had that part in there. I have reason to believe its in its sequential order. Will let you know when I find an answer. Thanks!
Trip
Haha sorry about the massive edit, I figured out how to place code in the comments ;) . I've been doing a lot of tracing, and its definately there. Occasionally I can see a glimpse of it, but only in a failed trace statement. Wierd right? I can't imagine how this works.
Trip
Still working on this. Its been one week so far, I havn't been able to break out anything. I have read every single url regarding parsing xml attributes, and I can not figure this out.
Trip
Hm. Not quite sure what you mean by a failed trace. If I understand correctly, if you trace 'e.target.data' in the complete handler, you get the correct xml? If so, I'd try simplifying your code, removing the tweens for now, and just trying to place your mc's once they're filled with content. There's a lot going on in your code, maybe the xml is not what's breaking things?
quoo
Awesome link, been looking for some definitive xml-parsing howto for as3 to no real avail.
Beau Martínez
A: 

The reason that my code at best only displayed one result from the XML List is because I instantiate a TextField outside of the loop that draws the var i from the XML's many nodes. To correctly display a textfield for each node, I need to instantiate the TextField for each var i. Like this :

function callThumbsW():void {
for (var i:Number = 0; i < my_totalW; i++) {

 var thumb_urlW = my_imagesW[i].thumb;
 var book = my_imagesW[i].TITLE;

 var textHolder:TextField = new TextField;
 container_mcW.addChild(textHolder);

This causes instant gratification.

Trip