A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Dynamic node targeting/retrieval

  1. #1
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378

    Dynamic node targeting/retrieval

    I'm working on an application for a client that keeps track of movies in an xml driven database. I can read/write to the xml file fine, but I wanted to optimize the "sorting" of his collection in the display to increase performance a bit more.

    There happens to be 3 separate list boxes, a button, and a check box. The first drop down contains different genre names (i.e: comedy, drama, action, adventure, etc), or the word "All" which simply means to use the entire database and should be disregarded hereafter.

    The next drop down contains a few more categories: Director, Actor, and Studio.

    The third drop down is conditional: if the user leaves the above drop down blank, this one doesn't appear. If it does appear, it is populated by a list of every unique director, actor, or publishing studio (respective to what the second list has selected). So if director is selected, you might see John Woo in there or something. If it's actor, you might find Matt Damon, etc etc.

    The last thing is the check box. This is just a small thing and all it does is specify the sort should contain only-new (read: unseen) movies or not.

    There's also the Sort button which performs the action.



    My problem is in defining a single function for repetitive use that can filter the XML list of <movie>'s repeatedly. Here's an example of the XML structure:


    <movie>
    <title></title>
    <releasedate></releasedate>
    <studio></studio>
    <runtime></runtime>
    <rating></rating>
    <imagepath></imagepath>
    <moviepath></moviepath>
    <format></format>
    <prating></prating>
    <apppath></apppath>
    <desc></desc>
    <actor></actor>
    <actor></actor>
    <actor></actor>
    <actor></actor>
    <actor></actor>
    <director></director>
    <genre></genre>
    <genre></genre>
    <id></id>
    <seen></seen>
    </movie>
    I have removed all the content to make it more clear, but please note that every single attribute of <movie> is treated as a string.

    So, this is as far as I have gotten with a function that theoretically should do what I want, but I am stuck with dynamically targeting the nodes.

    Actionscript Code:
    public function convert(dcl:XMLList) {
                var dcr:XML = new XML(<records></records>);
                var dca:Array = new Array();
               
                for each (item in dcl) {
                    dca.push(item);
                }
               
                dca.sortOn("title");
                for (var i = 0; i<dca.length; i++) {
                    dcr.appendChild(new XML(dca[i]));
                }
                trace("Convert: " + dcr.movie.length());
                return dcr;
            }

            public function getDataCopy() {
                var dcl:XMLList = data.records.children();
                return dcl;
            }

            public function filter(s1:String, target:String) {
                var dcl:XMLList = getDataCopy();
                dcl = dcl.(target.contains(s1)); // HERE IS WHERE IT ALL GOES WRONG
                trace("Filter: " + dcl.length());
                return dcl;
            }

    // EXAMPLE USAGE:
    // used to return an XML object to the display class for processing

    var returnData:XML = convert(filter("Action", "genre")); // these two strings are normally dynamically passed variables from whatever the user has selected in the drop down list boxes.

    In the above code in the filter() function, I can not seem to find a way to dynamically target the attribute of <movie>. The reason I need it in that fashion-- dcl.(target.contains(s1));-- is because I need to return -all- movies whose "target" attribute matches s1, and not just one.

    I have seriously scoured the internet for a little over a week now and have have already asked a few other people. Nobody seems to know how to get the target variable to seen as, for instance, the <genre> or <director> or <actor> attribute.

    Any help is extremely appreciated... sorry for the long post but I wanted to be clear!
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var tmp:XMLList = new XMLList(<dummynode></dummynode>);
    tmp.setName(target);
    tmp[0]=s1;
    trace(dcl[target].contains(tmp));

  3. #3
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    All that traces is true or false. I'm not interested in whether or not the movies have a "s1" attribute that matches "target"; A syntax like dcl.(actor.contains("Matt Damon")) returns a XMLList, not a boolean. The contains() function line is where I filter out all movies that don't meet the criteria.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  4. #4
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    so you're trying to access a node based on a string?

    var nodeName:String = "actor";
    var node:XMLList = myXML.child(nodeName);

    that will return the actor node in the movie xml. You can then access an attribute for that node

    var attributeName:String = "name";
    var nodeAttribute:XMLList = node.attribute(attributeName);
    lather yourself up with soap - soap arcade

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