A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] XMLList to an Array?

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103

    resolved [RESOLVED] XMLList to an Array?

    What is the process for feeding XMLList values to a URLRequest method?

    Say I have an array:

    code:
    var imageURLS:Array = ["images/image1.png", "images/image2.png", "images/image3.png"];


    Then I feed a loader instance:

    code:
    var loader:Loader = new Loader();
    loader.load(new URLRequest(imageURLS[0])); // imageURLS[0] traces 'string'
    addChild(loader);

    // works great, no problem...


    ...now say I want to bring these images in via XML rather than an array:

    code:
    var xmlData:XMLManager = new XMLManager("images.xml");
    xmlData.addEventListener(Event.COMPLETE, loadXML);
    xmlData.start();

    var pathList:XMLList = new XMLList();

    function loadXML(event:Event):void {
    pathList = xmlData.xmlContent.image.path.text();
    firstPath = pathList[0].toString();
    }

    trace(firstPath); // traces 'images/image1.png'
    trace(typeof(firstPath)); // traces 'string'

    trace(imageURLS[0]); // traces 'images/image1.png'
    trace(typeof(imageURLS[0])); // traces 'string'

    var loader:Loader = new Loader();
    loader.load(new URLRequest(firstPath));
    addChild(loader);

    // OUTPUT: 'Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found'


    Way I see it is the traces above are the same, where am I wrong?
    Last edited by madkat; 12-18-2009 at 05:18 PM.

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    By the looks of the code, you've got a timing issue. If you run all that at once, there's a chance the .xml isn't loaded by the time you call loader.load(new URLRequest(firstPath));

    Try creating a function called loadFirstImage() or something that loadXML calls.

    PHP Code:
    var pathList:XMLList;
    var 
    firstPath:String;

    function 
    loadXML(event:Event):void {
        
    pathList xmlData.xmlContent.image.path.text();
        
    firstPath pathList[0].toString();
            
    loadFirstImage();
    }

    function 
    loadFirstImage():void{
      var 
    loader:Loader = new Loader();
      
    loader.load(new URLRequest(firstPath)); 
      
    addChild(loader);


  3. #3
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103
    Thanks jAQUAN - I'll try that - sorry, missed the first line you posted.
    Last edited by madkat; 12-18-2009 at 05:56 PM.

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103
    By the looks of the code, you've got a timing issue. If you run all that at once, there's a chance the .xml isn't loaded by the time you call loader.load(new URLRequest(firstPath));
    Hot damn I think that's our answer man! Thank you thank you... this issue has plagued me for ages.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center