PDA

Click to See Complete Forum and Search --> : Displaying XML into Flash--



diavolo
04-18-2001, 08:11 AM
I am new to xml and I would like to change my current blog reader on my site from loading html to loading xml. How would I go about doing this? I know I need to do this:
//load the xml,
//parse the xml, and
//create a new object
-----------------------------
Here is my xml structure


<blog>
<entry>
<*date>Date<*/date>
<*time>Time Of Post<*/time>
<*text>News text<*/text>
<*links>Featured Links<*/links>
<*author>Person Posted<*/author>
</entry>
</blog>

---------------------------------------
my xml file:
http://www.stumede.com/flashkit/blog.xml
my not working swf file:
http://www.stumede.com/flashkit/xml.swf
----------------------------------------
I did try downloading some of the xml movies flashkit has, and understood very little on how to do this..
Any help or ideas on how to do this would be great.

Thanks,

sam
[Edited by diavolo on 04-18-2001 at 08:15 AM]

FlashGuru
04-18-2001, 08:27 AM
It would be better if it loaded html, loading variables is alot faster than parsing xml files.

I started by blog off with parsing xml and decided to change to loading html into a html enabled textfield!

diavolo
04-18-2001, 08:46 PM
good, that's the way mine is right now. I just want to learn more on how to import and xml file in flash. For instance, how would I just add xml text to flash? Thanks for your help Guy!

sam

enemem
04-19-2001, 05:28 AM
SORRY - LONG REPLY :)

well, it might be easier for you to read the help section on the XML object, but basically you do this:

- create a new XML object
var myXMLDoc = new XML();

- add an 'onload' event handler to your object
(this is the name of the function to call when the file has loaded)
myXMLDoc.onload = myOnloadFunction;

- load your XML file into the object
myXMLDoc.load("url");

once the file has loaded, the function myOnloadFunction is automatically called. use this function to either parse the XML document or to go to a part in the flash movie that handles this job.

I found that the easiest way is to include all the data as XML tag attributes rather than as text like you did, so you do:

<BLOGItem date="19th April 2001">
<LINK url="http:// 1" descr="this and that"/>
<LINK url="http:// 2" descr="this and that"/>
<LINK url="http:// 3" descr="this and that"/>
</BLOGItem>

( the /> at the end are automatic closing statements, you can also write <LINK ...></LINK> )

****, this is getting long!
anyway, have a look in the help sections under XML.attributes and XML.hasChildNodes and XML.childNodes etc. etc. and just experiment - that's what I did....

[I don't know anything about XML, maybe it's all wrong...]

enemem
04-19-2001, 05:29 AM
yeah - so, I'm a bit thick and didn't realise I had to format that bit as code....

how's that go?

enemem
04-19-2001, 05:52 AM
f*ck - and it should have been

onLoad (with capital L) instead of onload...

this is getting worse and worse :)

diavolo
04-19-2001, 08:51 AM
haha thanks man--this will help a great deal.:)

sam

Mistaderelict
04-19-2001, 12:59 PM
So will loading and parsing the XML work on the WEB?? I can't figure that out as of yet. I have a perfect XML newsfeed configured, but it will just NOT work on the web, only locally. Let me know if anyone has accomplished, because I've had no luck :(
[Edited by Mistaderelict on 04-19-2001 at 10:13 PM]

ZeroGhost
04-19-2001, 07:59 PM
Enemem,

Great post... xml was the last bit of flash trickery I have been putting off... as (my) luck would have I was asked to create some flash content that involves xml data (sure I can do that, I said "translation: if I say no then he'll think I am a wieny") ...anyways you probably saved me an hour or two of research... so thanks..

RAMpage2010
04-20-2001, 01:48 AM
I found the XML parsing to be a bit slippery. I have noticed that there are a lot of null nodes and silly things like myXML.firstChild.nextSibling.firstChild to be awkward as hell and inconsistent in the manner in which it seems to walk the nodes. For instance, if I take two steps forward and two steps backward in the XML, I *can* land up in a spot in the node structure that is not the same one I started that short little trip on. I believe this to be a flaw based on the timing of processing clicks.. like there is some mysterious invisible wait state in the low-level mouse routines... anyway

So what I did was basically do, is what almost everyone recomends. I place the nodes into an array just recently, and array that holds object that mimic the structure of the XML. here is some code fragments to illustrate what I mean.

quoteXML = new XML();
currentquote = new XML();
quoteXML.onload = setupXML;
quoteXML.load("http://..blahblah");
childrenArray = new Array();
CQ = new Array();
QuoteObject = new Object();
QuoteArray = new Array();
Qindx = 0;

// constructor function
function Quote () {
this.symbol="";
this.qtype="";
this.qOpenInterest="";
//..blah blah
}
// set the qsymbol text control to the value in the array.
function DisplayQuote() {
qsymbol = _level0.QuoteArray[_level0.Qindx].symbol;
//..blah blah
}

function AssembleQuoteArray () {
theseChildren = currentquote.childNodes;
CQ = theseChildren; // auto array construction :)
for (i=0; i<theseChildren.length; i++) {
if (CQ[i].attributes.name == "Symbol") {
QuoteArray.push(new Quote);
_level0.QuoteArray[_level0.Qindx].symbol = _
CQ[i].attributes.value;
qsymbol = CQ[i].attributes.value;
}
}
.. you get the idea even though my code looks atrocious on this display.

Hope that helps at least one poor bastard like me :)