Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
vilmar souza

Painless XML Translation AS2

Recommended Posts

Hi All,

 

About the Painless XML Translation AS2,

 

anyone know how to show an example of the functions:

bytesLoaded()
percentLoaded()
bytesTotal()

 

 

thanks!

 

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

Not really sure what you are referring to with "Painless XML Translation AS2".

 

Our LoaderMax tools like XMLLoader are only written for AS3.  

 

Try this article: http://www.kirupa.com/web/xml/XMLwithFlash3.htm (page 2 talks about tracking progress) 

Link to comment
Share on other sites

Thanks Carl,

is about the http://www.greensock.com/xmlparseras2/

Parser works great for me. Got a 2.0 Mb XML to load. Is there a way to monitor the loading progress?
How use the “bytesLoaded” and “bytesTotal”and “percentLoaded” properties  ? I don't found any example at moment.

Thanks!

Link to comment
Share on other sites

Ah, thanks for the link. XMLParser was a bit before my time;)

 

In order to get that info you need to basically ask your XMLParser object for it.

 

Paste this code into the XMLParser_sample.fla that comes with the download:

 

import com.greensock.dataTransfer.XMLParser;


//create a reference to your XMLParser
var myXML = XMLParser.load("myDocument.xml", onFinish, null, false, true);


function onFinish($success:Boolean, $parsedObject:Object, $xml:XML) { //This fhunction gets called as soon as the XML loads and gets parsed.
if ($success) {
displayResources($parsedObject);
showImage($parsedObject);


//REMOVE the enterFrame
delete _root.onEnterFrame;
} else {
trace("FAILED to load XML");
}
}


function displayResources($parsedObject:Object):Void {
var i:Number;
var books:Array = $parsedObject.Book;
for (i = 0; i < books.length; i++) {
display_tf.text += "Book " + i + ": " + books[i].name + " (ISDN: " + books[i].ISDN + ")\n";
}


var novels:Array = $parsedObject.Novel;
display_tf.text += "-----------------------------------------" + newline;
for (i = 0; i < novels.length; i++) {
display_tf.text += "Novel " + i + ": " + novels[i].name + " (Description: " + novels[i].Description[0].nodeValue + ")\n";
}
}


function showImage($parsedObject:Object):Void {
var l:Number = this.getNextHighestDepth();
var mc = this.createEmptyMovieClip("image" + l, l);
mc._x = 250;
mc._y = 220;
mc.loadMovie($parsedObject.Photo[0].url);
}


//Poll the loaded info onEnterFrame (delete enterFrame in finish event above);
this.onEnterFrame = function() {
trace(myXML.bytesLoaded + "/" + myXML.bytesTotal + " as percent = " + myXML.percentLoaded);
}

I've added some comments to the code. 

In order to test the progress effectively use Flash's bandwidth profiler when testing locally.

 

1: export swf

2: Menu : VIew > Simulate Download

 

Use View > Download Settings to configure a fake slow download speed like 14.4

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×