dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [F8] Add field to XML

  1. #1
    Senior Member
    Join Date
    Jun 2001
    Posts
    140

    [F8] Add field to XML

    Hi,
    I'm currently using an XML file to load an image and menu-name into a list component and would like to add a description field to this.
    I have added another attribute to my XML file called 'desc' so the file is now arranged:
    
    PHP Code:
    <xml>
        <
    listitem name="Le Mans 06, 0-5" url="http://www.dedicatedmicros.com/ukftp/FLVHUB/FLV/" thumb="1.jpg" desc="some text">
            <
    stream name="1.FLV" start="0" len="-1"/>
        </
    listitem
    After dropping a dynamic text field onto the stage instance named 'description', I have attempted to modify the xmllist.load code but despite not firing any errors, this has not resolved the issue:
    That code is as follows: (changes are proceeded by '//-')
    PHP Code:
    //-------------------------LIST SELECTION CHANGE-----------------------------
    //Add an event listener on the list, when it triggers, run the listListener function to repopulate the list
    list.addEventListener("change"listListener);


    //Function that loads the XML file, parses it, and builds the list of available video clips
        
    var xmllist = new XML();          //setup a variable to hold the XML
        
    xmllist.ignoreWhite true;
        
    xmllist.load"video_playlist.xml" );     //load the XML file
        //The following gets called when the XML has been loaded
        
    xmllist.onLoad = function( status )  {
            if ( !
    status )
                
    tracestatus );
            var 
    entries this.childNodes[0];
            var 
    playlists = {};
            var 
    nav = [];
    //-        var description = {};
    //-        var descrip = [];
            
    for ( var 0entries.childNodes.lengthi++ ) {
                var 
    entry entries.childNodes[i];
                if ( 
    entry.nodeName == "listitem" )
                    
    //builds array of video clip names
                    
    playlists[entry.attributes.name] = entry;
                else if ( 
    entry.nodeName == "menu" ) {
                    
    //builds array of available videos
                    
    for ( var 0entry.childNodes.lengthj++ )
                    
    nav[j] = playlists[entry.childNodes[j].attributes.name];
                    
    //-            if ( entry.nodeName == "desc" ) {
    //-                //builds array of descriptions
    //-                description[entry.attributes.desc] = entry;
    //-                for ( var k = 0; k < entry.childNodes.length; k++ )
    //-                descrip[k] = //-description[entry.childNodes[k].attributes.desc];
                
    }
                    
                } 
    //end else if
            
    //end if

            //sends the array of videos to the listbox UI
            
    list.dataProvider nav;
            
    desc.text descrip;
        } 
    //end xmllist.onload 
    Was hoping someone could help point me in the right direction as to where i'm going wrong with this one as i've attempted various things now but have not had success with any.

    If anyone can offer any assistance here I would be very appreciative,

    Thanks,
    Dave

  2. #2
    Grandmaster Flash
    Join Date
    Apr 2004
    Location
    Edinburgh, Scotland
    Posts
    139
    What does the code currently do? Does it populate anything at all into the dropdown?
    If it ain't broke, don't fix it.

  3. #3
    Senior Member
    Join Date
    Jun 2001
    Posts
    140
    Thanks for the reply,
    The code currently populates a list component with the 'listitem name' and, with the use of the cellrenderer class, thumbnail images within the listbox.
    All I basically want to do is add a new attribute to the XML doc in which I can store a description that will load into a dynamic textbox on selecteditem change.
    The commented out sections (code preceeded by '//-') is the code I have attempted to use to load in the contents of the description attribute from the XML doc.
    Am hoping you point out where I've gone wrong..

    Thanks

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    this is the method i use ( no exp. with cellrenderer class yet )
    to avoid conflict with reserved words i have changed - name,url,start
    and altered the format of the xml slightly

    hope you can adapt this to your project
    Code:
    xmllist = new XML();
    xmllist.ignoreWhite = true;
    xmllist.load("video_playlist.xml");
    
    xmllist.onLoad = function(){
    rootNode = xmllist.firstChild;
    leng = rootNode.childNodes.length;
    
     for(var i=0; i<leng; i++){
    nom = rootNode.childNodes[i].attributes.vname;
    vurl = rootNode.childNodes[i].attributes.vurl;
    thu = rootNode.childNodes[i].attributes.thumb;
    des = rootNode.childNodes[i].attributes.desc;
    str = rootNode.childNodes[i].attributes.stream;
    sta = rootNode.childNodes[i].attributes.vstart;
    len = rootNode.childNodes[i].attributes.len;
    
    list.addItemAt(i,{label:nom, vurl:vurl, thu:thu,
    desc:des, str:str, sta:sta, len:len})      
    } 
    } 
    
    obj2 = new Object();
    obj2.change = function(comp){
    vid = comp.target.selectedItem.label;  trace(vid);
    url = comp.target.selectedItem.vurl;  trace(url);
    thumb = comp.target.selectedItem.thu;  trace(thumb);
    desc = comp.target.selectedItem.desc;  trace(desc);
    stream = comp.target.selectedItem.str;  trace(stream);
    vstart = comp.target.selectedItem.sta;  trace(vstart);
    lenth = comp.target.selectedItem.len;  trace(lenth);
    trace("---------------");
    _root.description.text = desc;
    }
    list.addEventListener("change", obj2);
    PHP Code:
    <xml>
    <
    listitem vname="Le Mans 06, 0-5" vurl="http://www.dedicatedmicros.com/ukftp/FLVHUB/FLV1/" thumb="1.jpg" desc="some text" stream ="1.FLV" vstart="0" len="-1">
    </
    listitem>
    <
    listitem vname="Le Mans 05, 0-4" vurl="http://www.dedicatedmicros.com/ukftp/FLVHUB/FLV2/" thumb="2.jpg" desc="more text" stream ="2.FLV" vstart="10" len="10">
    </
    listitem
    </
    xml

  5. #5
    Senior Member
    Join Date
    Jun 2001
    Posts
    140
    Thanks a lot! will go through that tonight and see if I can get it working

    Thx again!
    Dave

  6. #6
    Senior Member
    Join Date
    Jun 2001
    Posts
    140
    Hi, thanks again for your assistance..

    Tried your code and got the description box working but it crippled the list in the process. Have attempted to converge the two together but am not great with XML and am beginning to run out of ideas on this one.
    Have uploaded my FLA etc and was hoping you could have a look and see if you can work out where I've gone wrong: (all files are listed at the following)
    http://www.dedicatedmicros.com/ukftp/docs/
    or, i've also zipped it all up for convnience if you prefer
    http://www.dedicatedmicros.com/ukftp...ideosource.zip

    Thanks for the advice,
    Dave

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    sorry , no can do
    mx2004 (version 7) here

  8. #8
    Senior Member
    Join Date
    Jun 2001
    Posts
    140
    ahh well.. thanks for trying anyway

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