A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Displaying XML into Flash--

  1. #1

    Samuel C. Granato
    Multimedia Utopia
    Moderator

    Join Date
    Jun 2000
    Posts
    410
    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
    Code:
    <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]

  2. #2
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    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!

  3. #3

    Samuel C. Granato
    Multimedia Utopia
    Moderator

    Join Date
    Jun 2000
    Posts
    410
    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

  4. #4
    Senior Member
    Join Date
    Feb 2001
    Posts
    1,835
    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...]





  5. #5
    Senior Member
    Join Date
    Feb 2001
    Posts
    1,835

    yeah - so, I'm a bit thick and didn't realise I had to format that bit as code....

    how's that go?

  6. #6
    Senior Member
    Join Date
    Feb 2001
    Posts
    1,835
    f*ck - and it should have been

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

    this is getting worse and worse

  7. #7

    Samuel C. Granato
    Multimedia Utopia
    Moderator

    Join Date
    Jun 2000
    Posts
    410
    haha thanks man--this will help a great deal.

    sam

  8. #8
    Junior Member
    Join Date
    Nov 2000
    Posts
    23
    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]

  9. #9

    Enemem

    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..

  10. #10
    Senior Member
    Join Date
    Apr 2001
    Posts
    108

    Lightbulb

    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

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center