A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: (AS2) Track XML load time

  1. #1
    Senior Member hts5000's Avatar
    Join Date
    Oct 2007
    Posts
    160

    (AS2) Track XML load time

    Does anyone know of a way to track the load time of an XML document? I have an xml document that has over 150,000 lines and it takes a little time to load. I am ok with the load time in general however I would like to create a preloader to tack its process. Does anyone know how this can be done..if at all???

    I have tried putting the xml load/onLoad code in a movie clip and use getBytesTotal and getBytesLoaded to track the mc progress but it seems as though when that mc is loaded the application freezes until the xml is fully loaded. Any ideas?

  2. #2
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    Rather than kill myself explaining it.

    http://www.kirupa.com/web/xml/XMLwithFlash3.htm

    Page 2 is probably of interest but you might read the whole article.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  3. #3
    Senior Member hts5000's Avatar
    Join Date
    Oct 2007
    Posts
    160
    Thanks mneil for posting that link. However, I did try that and I am still running into issues. I read the entire article and using their method the program is still freezing. I posted a test fla and an excessively large xml file, is there any way you could take a look at it and tell me what I am doing wrong? Any help would be greatly appreciated.
    Attached Files Attached Files

  4. #4
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    You're very close. A couple of issues.

    You checked this.target in the enterFrame loop. target wasn't a property of this and so would always return 0. Also, you should kill the enterFrame when it is loaded. Instead of checking target check the loaded xml's getBytesLoaded and Total. And, it's not necessary, but you should set the datatype of the XML to XML. Here's the code:

    PHP Code:
    var my_xml:XML = new XML();
    my_xml.onLoad = function(success) {
        if (
    success) {
            
    trace("Done");
        }
    };
    var 
    scale 0;
    preloadbar_mc.onEnterFrame = function() {
        var 
    loaded my_xml.getBytesLoaded();
        var 
    total my_xml.getBytesTotal();    
        if (
    loaded && total) {
            var 
    percent loaded/total;
            
    scale 100*percent;
            
    this.onEnterFrame null
            delete this
    .onEnterFrame;
        }
        
    this._xscale scale;
    };
    preloadbar_mc.target my_xml;

    my_xml.load("loadTest.xml"); 
    This works for me. Although, it does cause a little lag before executing. However, it didn't crash like when I tried to run yours. Also, your pc is going to cache the xml and therefore you can't test the preloader bar actually firing. At least not but clicking test or run movie. However, once you've clicked control>test movie in the pop up box click on view>download settings and set it to something like dsl, and then click on view>simulate download. This will attempt to simulate the download from someone using a dsl connection. To more accurately test the speed if you'd like I'd recommend sloppy if it's still around (I'm sure it is). Its a free JAVA proxy to simulate download speeds and it's fairly accurate. Flash does a good job at it though too.

    Sorry for the poor grammar this morning.
    Last edited by mneil; 01-07-2011 at 12:09 PM. Reason: I sounded as if I were an ESL student. no offense.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  5. #5
    Senior Member hts5000's Avatar
    Join Date
    Oct 2007
    Posts
    160
    Thanks mneil, it seems to work now. Quite honestly I was only copy and pasting the code from that tutorial (not that the code I was working before was any better).

    Having said that I wasn't even sure what "this.target" even was. I know what "this" is but don't know what "Target" is and how to even set that type of property.

    Question though, What does "this.onEnterFrame = null" do? I always kill my onEnterFrames with "delete this.onEnterFrame" like you did in the following line. So I am not sure what the other code is doing.

    Thanks again for you help. You are a life/code saver.

  6. #6
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    target would be a property of this. And this would be a reference to preloadbar_mc in the enterframe scope. Movieclips don't have a default property of target, and you didn't set one, so it's null.

    Setting the onEnterFrame to null before deleting it is a habit of mine. 2 reasons I do it:

    1) setting it to null takes up less memory than the function it was assigned to.

    2) when it's null it hits the garbage collector.

    I never really really got into the GC with AS2 but when I used to write it I did it that way and believe that's the reason I did it. Now that it's been 3 years I can't remember. Setting something to null in AS3 doesn't mark it for collection but regardless it saves on memory I believe. That's all. Not a big issue in your case.
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

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