dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Can't preload XML data!!

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    260

    Can't preload XML data!!

    Hello,

    I've got the following code working all fine but I have no idea how to put a preloader on it. Nothing I try works. Is it possible to do? Any help would be grately appreciated.
    Code:
    var xml:XML = new XML();
    xml.ignoreWhite = true;
    xml.load("icons.xml");
    
    xml.onLoad = function()
    {
    	var nodes = this.firstChild.childNodes;
    	numOfItems = nodes.length;
    	for (var i=0; i<numOfItems; i++)
    	{
    		var t = home.attachMovie("item","item"+i,i+1);
    		t.angle = i * ((Math.PI*2)/numOfItems);
    		t.onEnterFrame = mover;	
    		t.toolText = nodes[i].attributes.tooltip;
    		t.theTitle.text = nodes[i].attributes.title;
    		t.content = nodes[i].attributes.content;
    		t.title = nodes[i].attributes.title;
    		t.feature1 = nodes[i].attributes.feature1;
    		t.feature2 = nodes[i].attributes.feature2;
    		t.feature3 = nodes[i].attributes.feature3;
    		t.feature4 = nodes[i].attributes.feature4;
    		t.buynow = nodes[i].attributes.buynow;
    		t.icon.inner.loadMovie(nodes[i].attributes.image);
    		t.ref.inner.loadMovie(nodes[i].attributes.image);
    		t.icon.onRollOver = over;
    		t.icon.onRollOut = out;
    		t.icon.onRelease = released;
    	}
    }
    Cheers
    Matt

  2. #2
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    you can try this:

    PHP Code:
    // create a new XML document
    var xml:XML = new XML();
    xml.ignoreWhite true;
    xml.onLoad = function() {
        
    clearInterval(timer);
        var 
    nodes this.firstChild.childNodes;
        
    numOfItems nodes.length;
        for (var 
    0numOfItemsi++) {
            var 
    home.attachMovie("item""item" i1);
            
    t.angle * ((Math.PI 2) / numOfItems);
            
    t.onEnterFrame mover;
            
    t.toolText nodes[i].attributes.tooltip;
            
    t.theTitle.text nodes[i].attributes.title;
            
    t.content nodes[i].attributes.content;
            
    t.title nodes[i].attributes.title;
            
    t.feature1 nodes[i].attributes.feature1;
            
    t.feature2 nodes[i].attributes.feature2;
            
    t.feature3 nodes[i].attributes.feature3;
            
    t.feature4 nodes[i].attributes.feature4;
            
    t.buynow nodes[i].attributes.buynow;
            
    t.icon.inner.loadMovie(nodes[i].attributes.image);
            
    t.ref.inner.loadMovie(nodes[i].attributes.image);
            
    t.icon.onRollOver over;
            
    t.icon.onRollOut out;
            
    t.icon.onRelease released;
        }
    };
    xml.load("icons.xml");
    var 
    xmlProgress = function (xmlObj:XML) {
        var 
    bytesLoaded:Number xmlObj.getBytesLoaded();
        var 
    bytesTotal:Number xmlObj.getBytesTotal();
        var 
    percentLoaded:Number Math.floor((bytesLoaded bytesTotal) * 100);
        
    trace("milliseconds elapsed: " getTimer());
        
    trace("bytesLoaded: " bytesLoaded);
        
    trace("bytesTotal: " bytesTotal);
        
    trace("percent loaded: " percentLoaded);
        
    trace("---------------------------------");
    };
    var 
    timer:Number setInterval(xmlProgress100xml); 
    should work with your set-up..

    but I think the XML needs to be fairly large or the preloader will be very quick...no?

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    260
    Hi,
    Thanks for your reply. That's a method I tried but it wouldn't work. My XML isn't very large really, it's the images that the xml is referencing that are the problem. I might be on the wrong track with the xml loading question.

    Matt

  4. #4
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    what wouldnt work?

    1.) you asked about preloading your XML... (not images)
    2.) if you want to load you images use the MovieClipLoader() class...

  5. #5
    Senior Member
    Join Date
    Apr 2001
    Posts
    260
    Apologies for that I think I've made a mistake.
    I have the image names in the xml and therefore I mistakingly assumed that loading the xml would load the images too.
    I don't need to load the xml it's the images I need to load.

    Thank you for your reply - I'll do some research into the MovieClipLoader() class.

    Matt

  6. #6
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    np-

    there is a link in my footer called clipLoader... it will explain how to use it..once you do it a few times.. its EASY.. and very nice to use..

  7. #7
    Member
    Join Date
    Oct 2006
    Location
    UK
    Posts
    43
    Matt. Did you find a resolution to this? I find myself in the exact same position trying to load all my files in this onLoad function before I want to show them.

    Tim

  8. #8
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    you need to load them in a place holder or something off-stage/non-visible until you are ready for it to be seen.

  9. #9
    Member
    Join Date
    Oct 2006
    Location
    UK
    Posts
    43
    I think I didn't explain it all that well. I've posted my exact problem here.

    http://board.flashkit.com/board/showthread.php?t=757746

    If you can help me out that would be brilliant.

    Tim

  10. #10
    Senior Member
    Join Date
    Apr 2001
    Posts
    260
    Hi Tim,

    Whispers' solution was exactly what I needed and worked perfectly. Basically, I load all of the images into my holder either off screen, or under a mask and once they are all in I can bring them on nicely.
    I think I understand what you're problem might be though. The XML files aren't part of the main swf preloader? I would suggest having two - one for the xml, and one for everything else.

    Matt

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