I'm having some problems getting a flash application (in AS3) to search for a specific element value inside a xml. I have the following xml file.
<clientlist>
<pessoa>
<id>0140</id>
<nome>Maria Manuela</nome>
<email>mariamanuela@gmail.com</email>
<contacto开发者_JAVA百科>969876543</contacto>
</pessoa>
<pessoa>
<id>0141</id>
<nome>Maria Jose</nome>
<email/>
<contacto>961234567</contacto>
</pessoa>
<pessoa>
<clientlist>
I have a "search" field where, supposedly, I would type a name and would get an array of "pessoa"s, but I am having some problems making the loop happen.
So, imagine I would search for "Maria", I wanted to get a:
trace(PessoaArray[0]) =
<id>0140</id>
<nome>Maria Manuela</nome>
<email>mariamanuela@gmail.com</email>
<contacto>967060255</contacto>
trace(PessoaArray[1]) =
<id>0141</id>
<nome>Maria Jose</nome>
<email/>
<contacto>968496127</contacto>
Can anyone help me out? I'm not new to flash AS3 (even though i'm not exactly a pro), but its my first time messing with XML files.
Thank you.
Marco Roberto.
the short answer: xmlData.*.(nome == $name))
the long answer...
tested this in a FLA with a textfield_tf
and button_btn
import flash.events.MouseEvent;
var $data:XML = <clientlist>
<pessoa>
<id>0140</id>
<nome>Maria Manuela</nome>
<email>mariamanuela@gmail.com</email>
<contacto>969876543</contacto>
</pessoa>
<pessoa>
<id>0141</id>
<nome>Maria Jose</nome>
<email/>
<contacto>961234567</contacto>
</pessoa>
</clientlist>;
_btn.addEventListener(MouseEvent.CLICK,onClick);
function onClick($e:MouseEvent):void{
trace($data.*.(nome == _tf.text))
}
精彩评论