I am working on a project that calls and searches an XML sheet that looks like this:
<Searchtext Wordlookup="john smith">
<location>$1</location>
<Name>john smith</Name>
</Searchtext>
and it continues like this for about 100+ people.
Now, my flash takes this data and allows the user to either click on a textbox (whose e.target.data.text is matched up to the xml using @Wordlookup) or type in the name of the person (again matching the textbox's content to @Wordlookup) which results in the location of that person lighting up (MC's are named the same as the location node for each). This end works perfectly fine using this code:
var result:String = xmldata.Searchtext.(@Wordlookup == inputTxt.text.toLowerCase()).location.toString();
Now I want to do the opposite; click on a location, and the code will match up that movieclip's name to a location in my xml, and light up that location, and output the person's name in the textbox. Only problem in that Flash apparently thinks a node in my xml is now a variable that is undefined. I have looked high and low for a solution, but I just can't seem to solve it (it is probably simple, and I'll facepalm myself) The error inducing code is this:
var resultz:String = xmldata.Searchtext.(location.text() == inputTxt2.text()).Name.toString();
And the error produced is this: ReferenceError: Error #1065: Variable location is not defined.
EDIT: I originally had inputTxt2.text as e.target.name, but I'm throwing it in a textbox for now just so I can see it's outputting something that will match my location nodes.
Not sure exactly why this is happening, thank you in advance for any help!
ANOTHER EDIT: So adding .*. :
var resultz:String = xmldata.*.Searchtext.(location.text() == inputTxt2.text()).Name.toString();
stopped it from creating th node as a variable, but it still returns null. Is there a better way to return the name from the matching location? It seems like it just isn't recognizing that the MC's name matches nodes in the XML....
var xmldata:XML = new XML(
<root>
<Searchtext Wordlookup="john smith">
<location>$1</location>
<Name>john smith</Name>
</Searchtext>
</root>
)
var result1:String = xmldata.Searchtext.(@Wordlookup == "john smith").location.toString();
trace(result1) // traces $1
var result2:String = xmldata.Searchtext.(location == "$1").Name.toString()
trace(result2) // traces john smith
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.