Jump to content
Search Community

Painless XML Translation AS2

vilmar souza test
Moderator Tag

Recommended Posts

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.
×
×
  • Create New...