A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] [as/xml]displaying xml in the field

  1. #1
    Junior Member
    Join Date
    Dec 2005
    Posts
    25

    [F8] [as/xml]displaying xml in the field

    Hi i have one problem - i made for my friends Web and we have there some kind of timetable. It is in the flash menu so I need to show there our shows - i want to display only the nearest to the today date. http://www.teamc.aplus.pl/ququ/noc/ I want to display it below " Najblizszy wystep". As you see i have three words there ( so there will be three dynamicfields ) - miejsce ( place where they will be playing ), data ( date ) and godzina ( hour of the show ). I have problem - how to built xml file? If I put there about 10 shows so need I give every show an unique id ? like
    Code:
    <miejsce1>paris</miejsce1>
    <data1>19.02.2007</data1>
    <godzina1>19.00</godzina1>
    
    <miejsce2>warsaw</miejsce2>
    <data2>19.03.2007</data2>
    <godzina2>18.00</godzina2>
    
    <miejsce3>sopot</miejsce3>
    <data3>10.12.2007</data3>
    <godzina3>17.00</godzina3>
    
    or can i simple do:
    
    <miejsce>paris</miejsce>
    <data>19.02.2007</data>
    <godzina>19.00</godzina>
    
    <miejsce>warsaw</miejsce>
    <data>19.03.2007</data>
    <godzina>18.00</godzina>
    
    <miejsce>sopot</miejsce>
    <data>10.12.2007</data>
    <godzina>17.00</godzina>
    and flash will display only first? Is there any already made script? or any tutorial which will show me how to do it? regards

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    can you simplify your xml to -
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <shows>
    <show miejsce="paris" data="19.02.2007" godzina="19.00"></show>

    <show miejsce="warsaw" data="19.03.2007" godzina="18.00"></show>

    <show miejsce="sopot" data="10.12.2007" godzina="17.00"></show>
    </shows>
    if so, use this method in Flash -
    Code:
    showsArray = new Array();
    
    _xml = new XML();
    _xml.ignoreWhite = true;
    _xml.load("shows.xml");
    
    _xml.onLoad = function(){
    aNode = this.firstChild.childNodes;
    len = aNode.length;
    for(var n=0; n!=len; n++){
    obj = {};
    obj.miejsce = aNode[n].attributes.miejsce;
    obj.date = aNode[n].attributes.data;
    obj.godzina = aNode[n].attributes.godzina;
    showsArray[n] = obj;
    }
    // dynamic textfields - instance names - 
    // theShow, theDate, theTime
    theShow.text = showsArray[0].miejsce;
    theDate.text = showsArray[0].date;
    theTime.text = showsArray[0].godzina;
    };
    hth

  3. #3
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    There are some different ways to write valid XML.
    Taking on your second piece of code, here's one:
    Code:
    <shows>
    	<show>
    		<miejsce>paris</miejsce>
    		<data>19.02.2007</data>
    		<godzina>19.00</godzina>
    	</show>
    	<show>
    		<miejsce>warsaw</miejsce>
    		<data>19.03.2007</data>
    		<godzina>18.00</godzina>
    	</show>
    	<show>
    		<miejsce>sopot</miejsce>
    		<data>10.12.2007</data>
    		<godzina>17.00</godzina>
    	</show>
    </shows>
    But here's another, which I'd use because it's easier to deal with in Flash:
    Code:
    <shows>
    	<show miejsce="paris" data="19.02.2007" godzina="19.00" />
    	<show miejsce="warsaw" data="19.03.2007" godzina="18.00" />
    	<show miejsce="sopot" data="10.12.2007" godzina="17.00" />
    </shows>
    Here's the ActionScript to deal with it:
    code:

    var my_xml:XML = new XML();
    my_xml.ignoreWhite = true;
    my_xml.onLoad = function(success)
    {
    if (success)
    {
    var temp:Array = this.firstChild.childNodes;
    var n:Number = temp.length;
    for (var i = 0; i < n; i++)
    {
    trace("*** show " + (i + 1) + " ***");
    trace(temp[i].attributes.miejsce);
    trace(temp[i].attributes.data);
    trace(temp[i].attributes.godzina);
    }
    }
    else
    {
    trace("error loading xml");
    }
    };
    my_xml.load("xml_show.xml");

    Attached Files Attached Files

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    a_modified_dog,

    no comments...


  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    nunomira

    great minds think alike


  6. #6
    Junior Member
    Join Date
    Dec 2005
    Posts
    25
    its great thank You aah and good night :]

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