views:

26

answers:

3

OK, it's probably easiest now to explain my problem like this, I am able to write the name of my xml file that needs to be loaded to a dynamic textfield on the stage, however, I don't seem to be able to access it after this and strip the necessary data from it, here's my code:

var tf:TextField = new TextField();
tf.autoSize=TextFieldAutoSize.LEFT;
tf.border=true;
addChild(tf);

try {
var keyStr:String;
var valueStr:String;
var paramObj:Object=LoaderInfo(this.root.loaderInfo).parameters;
 for (keyStr in paramObj) {
 valueStr=String(paramObj[keyStr]);
 tf.appendText(valueStr + "\n");
}
} catch (error:Error) {
 tf.appendText("error");
}

// load and parse the xml
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest(valueStr));

function LoadXML(e:Event):void {
xmlData=new XML(e.target.data);
xmlData.ignoreWhite = true;
var items:XMLList = xmlData.resource;
var tarray:Array = new Array();

 for each (var resource:XML in items) {
  tarray.push(resource.@src);
 }

  c3 = tarray.pop();
  c2 = tarray.pop();
  c1 = tarray.pop();

Where my xml looks like this, anyone see what I'm doing wrong?

 <?xml version="1.0" encoding="utf-8"?>
 <xml>
 <resource id="thing1" src="swf1.swf" />
 <resource id="thing2" src="swf2.swf" />
 <resource id="thing3" src="swf3.swf" />
 </xml>

Many thanks

// UPDATE

OK, this scenario now works fine, when I directly load the xml:

                    var xmlLoader:URLLoader = new URLLoader();
        var xmlData:XML = new XML();
        xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
        xmlLoader.load(new URLRequest("testxml.xml"));   

        function LoadXML(e:Event):void {
        xmlData=new XML(e.target.data);
        xmlData.ignoreWhite = true;
        var items:XMLList = xmlData.resource;
        var tarray:Array = new Array();

            for each (var resource:XML in items) {
                tarray.push(resource.@src);
            }

            c3 = tarray.pop();
            c2 = tarray.pop();
            c1 = tarray.pop();

            trace("c1"+c1+"c2"+c2+"c3"+c3); // traces my swf files

Then later, code attached to a button successfully loads the file:

var swf:MovieClip;
var loader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest(c1); 

So all I want to do now is to be able to achieve the same thing but loading the xml with loadvars as I did before, from my traces it seems there is a scope issue, but I'm not sure why if "c1" can be referenced like it is above..?

thanks

A: 

You're not really showing the part of the code that's relevant. Here we see that you get your XML url from flashvars and assign the XML data to an array.

The assignment to c1, c2 & c3 looks a bit odd. Why do you use the pop() method?

If tarray is an array of images url, why don't you use tarray's data to load your images from?

Check the trace statements for errors!

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.net.URLRequest;

for each( var url:String in tarray )
{
    var loader:Loader = new Loader();
    var info:LoaderInfo = loader.contentLoaderInfo;

    info.addEventListener(Event.COMPLETE , completeHandler );
    info.addEventListener(IOErrorEvent.IO_ERROR , errorHandler );

    loader.load(new URLRequest(url));
}

function completeHandler(event:Event):void
{
 trace( event );
}

function errorHandler(event:IOErrorEvent):void
{
 trace( event );
}


PatrickS
Thank you, one of my problems is I can't use trace statements to look for errors, as the xml the gives me the localtion of my swf files is loaded in through flashvars, so I need to test it in it's html page, but Ill try to replicate your scenario above, thanks
Jack
you could use a test xml file , directly loading with URLLoader, and go back to flashvars when all is working fine
PatrickS
You are right, I'm trying to do too much at once, Ill do it step by step and see how I go, thanks
Jack
A: 

Hi, Well this is where I'm having a problem, any attempt to try to use this data I think I have control over fails, for example

var swf:MovieClip;
var loader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest(c1);    
loader.load(defaultSWF);

Do you see what I mean? I thought popping the items off the array would allow me to simply use c1, c2 etc to manipulate them.

Many thanks

Jack
check the edited code!
PatrickS
A: 

Try to use trace(xmlData) to make sure you actually got XML loaded.

Does your code produce any errors?

ambienthack
Hi, I'm certain the xml gets loaded but I'm just going to retest with my stripped down scenario now
Jack