OZONE Asylum
Forums
XML - XSL - XSLT - XHTML - CSS - DOM
Action Script with XML
This page's ID:
11009
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Clarify what we are dealing with here - people's first and last names, or products with item numbers. If the former, the search loop is somewhat complicated by the fact that there could be several people with the same last name - the search doesn't want to terminate with the first match. If the latter, then presumably each sku or product ID is unique and thus the search CAN terminate at the first match. Using attributes as you indicated in your example is a more Flash-friendly way to structure xml. That's a plus. In your example, I think I'd just bag the index stuff and go straight for the detail. Just eliminate the index node entirely. In the example following, it's assumed there is no index node. I'd start by creating 2 arrays: lastArray, firstArray. code sort of like this (untested, but for an example) [code] lastArray = new Array(); firstArray = new Array(); myXML = new XML(); myXML.ignoreWhite = true; myXML.onLoad = function (success) { if (success) { rootNode = this.firstChild;//use of "this" keyword refers to the myXML object numEntries = rootNode.childNodes.length; for (var i=0; i<numEntries, i++) { lastArray.push(rootNode.childNodes[i].attributes.last; firstArray.push(rootNode.childNodes[i].attributes.first; } }else{trace("failed to load"); } [/code] hah. Top of my head, probably won't work as written, but that's the general idea. Load up two arrays with the data. Then the movie would have an input text field into which you would enter the last name, maybe called search_txt, and a "search" button. The button would have an onRelease function: [code] onRelease = function() { findItem(search_txt.text);//pass input content as argument to findItem function } [/code] which would trigger a loop which would do something along the lines of: [code] function findItem (searchString) { var numRecords = lastArray.length; for (var i = 0; i<numRecords; i++) { if(lastArray[i] == searchString) { return i; } } } [/code] So now "i" is returned as the index of the matching item in the array and you could pull the matching "i" item from firstArray and display the combined results somewhere. Again - all this is top of head stuff, and most likely won't work as written but it's how I would approach this task. You would also want some mechanism to clear the contents of the search field, some mechanism to report a failure to find a match and, as stated earlier, some recursive mechanism to continue checking for additional matches if your items aren't guaranteed to be unique. Help some?
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »