The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 6 of 6

Thread: Auto Reload XML in Flash

  1. #1

    Auto Reload XML in Flash

    Hi,
    I need to reload XML data in Flash as soon as the XML has been updated from back-end.
    I have gone through News Ticker Tutorial and It Worked fine.
    Here is the link of that tutorial for your reference: http://www.kirupa.com/developer/mx2004/newsticker.htm
    I customized the code little bit (am not a flash developer ). In the timer function, I put the xmlData.load... in order to reload the file. Luckily it worked but still didn't fulfil my requirement. When the condition p==total fulfils, it reloads the XML file but fade-in and fadeout the first displayed news very quickly, without any delay and rest of the news works fine. I have spent days to resolve this issue but in vain. Plzzzzzzzzzzzzz help me out. Here is the modification in red colour.

    Code:
    function loadXML(loaded) {
        if (loaded) {
            xmlNode = this.firstChild;
            caption = [];
            detail = [];
            from = [];
            total = xmlNode.childNodes.length;
            for (i=0; i<total; i++) {
                caption[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                detail[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
                from[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
            }
            first_item();
        } else {
            content = "file not loaded!";
        }
    }
    
    
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("Z:/news_ho.xml?blarg=" + new Date().getTime());
    
    
    
    
    function first_item() {
        delay = 3000;
        p = 0;
        display(p);
        p++;
    }
    function timer() {
        myInterval = setInterval(ticker, delay);
        function ticker() {
            clearInterval(myInterval);
            if (p == total) {
                xmlData.load("Z:/news_ho.xml?blarg=" + new Date().getTime());
                p = 0;
            }
            fadeout();
        }
    }
    function display(pos) {
        over = new TextFormat();
        over.underline = true;
        //
        out = new TextFormat();
        out.underline = false;
        //
        TitleMC.newsTitle._alpha = 100;
        TitleMC.newsTitle.text = caption[pos];
        
        newsMC.newsText._alpha = 100;
        newsMC.newsText.text = detail[pos];
        
        PostedMC.Postedtxt._alpha = 100;
        PostedMC.Postedtxt.text = from[pos];
        
        timer();
    }
    function fadeout() {
        this.onEnterFrame = function() {
            if (newsMC.newsText._alpha>=0) {
                newsMC.newsText._alpha -= 5;
                TitleMC.newsTitle._alpha -= 5;
                PostedMC.Postedtxt._alpha -= 5;
            } else {
                display(p);
                p++;
                delete this.onEnterFrame;
            }
        };
    }

    Thanks,
    Abdul
    Last edited by wahababd; May 9th, 2012 at 10:54 AM.

  2. #2
    Just now i have updated this thread. (Posted the whole code for better understanding)

  3. #3
    1,391
    posts
    Registered User
    when you call load, it also 'restarts' the system by invoking loadXML() then calls first_item() which also calls the timer() method again creating the quick iteration of the first element - you'll need to call a different method or by-pass that call on reloading - the system should be set up to continue as normal - however, you should also 'wait' for the xml to load before proceeding

  4. #4
    Dear cbeech,
    Thanks for your reply. Can you please guide me how to modify the code because am not a developer . Will really appreciate your help in this regard.

  5. #5
    1,391
    posts
    Registered User
    ok - so really the issue here is that loadXML calls first_item() on success - so we need to control that - see the display doesn't care what data is in the queue, so we should be able to replace that at any time, as long as we don't also invoke a 'restart' of the timing sequence

    - so with this code we could simply add a variable to help - BUT we'll also need to change the condition that checks the length of the array, so that on a reload while the system is in operation we don't result with p being out of range - so making these adjustments should do the trick:
    Code:
    var initialized:Boolean = false;
    
    function first_item():Void {
        if( initialized ) return;
        initialized = true;
        delay = 3000;
        p = 0;
        display(p);
        p++;
    }
    
    function timer() {
        myInterval = setInterval(ticker, delay);
        function ticker() {
            clearInterval(myInterval);
            if (p >= total) {
                xmlData.load("Z:/news_ho.xml?blarg=" + new Date().getTime());
                p = 0;
            }
            fadeout();
        }
    }
    under this code, it is difficult to provide a 'hold' until the xml is loaded since methods are 'chained' together - so under this solution, it is likely (more like probably) that it will repeat the 'first' story in the previous load while the new data is loading
    Last edited by cbeech; May 10th, 2012 at 10:50 AM.

  6. #6
    Thank you very much cbeech for all your help and quick response. The code works perfectly fine now

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012