You are again leaving a lot of room for interpretations. I mean, what is item2
in your if
conditions? String
, Boolean
, XMLNode
, etc? Do you maybe also need to access the examine
and chat
nodes in some situations? Your code access action
no matter of the state
, but there is only a single action state in your XML example?
Anyways, here's a basic E4X style example for dynamically accessing nodes by their name and their id
attributes:
var itemName:String = 'item2';
var interactionType:String = 'examine';
var stateId:uint = 1;
var messageId:uint = 2;
var message:XMLList = messageXML.items[itemName].interact[interactionType].state.(@id == stateId).message.(@id == messageId);
This equals the following "static" path
messageXML.items.item2.interact.examine.state.(@id == 1).message.(@id == 2)
so message
would contain the node with the text This is the first time I have seen item 2
.
See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html for more information on XML processing.