开发者

AS3-XML How to do a preloader while loading the xml?

What and where should the codes be added to show a preloader while xml is being loaded? Or I do not need to have one?

//Load gallery.xm开发者_如何学Pythonl
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("gallery.xml"));

function LoadXML(e:Event):void 
{
    xmlData = new XML(e.target.data);
    ParseProject(xmlData);
}

function ParseProject(projectInput:XML):void 
{
    trace("XML Output");
    trace("------------------------");

    var projectAttributes:XMLList = projectInput.project.attributes();

    for each (var projectName:XML in projectAttributes) 
    {
        trace(projectName);
        var projectDP:XMLList = projectInput.project.(@name == projectName).displayP;
        trace(projectDP);
    }
}


You can listen for a ProgressEvent:

import flash.events.ProgressEvent
xmlLoader.addEventListener(ProgressEvent.PROGRESS, _onProgress);
function _onProgress(e:ProgressEvent):void {
            //do whatever you need.
    trace( "loaded: ", e.bytesLoaded, " total: ", e.bytesTotal);
}

As to whether you should use one or not, it's up to you. Generally speaking, thou, it is a good idea to let the user know what is going on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜