# Call XML data in input text field, show in dynamic text field. Need a little help!

**URL:** https://forum.kirupa.com/t/call-xml-data-in-input-text-field-show-in-dynamic-text-field-need-a-little-help/329569
**Category:** Uncategorized
**Created:** [September 16, 2012, 12:52am UTC](https://forum.kirupa.com/t/call-xml-data-in-input-text-field-show-in-dynamic-text-field-need-a-little-help/329569 "2012-09-16T00:52:30Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![James070](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@James070](https://forum.kirupa.com/u/James070)
#### Post date: [September 16, 2012, 12:52am UTC](https://forum.kirupa.com/t/call-xml-data-in-input-text-field-show-in-dynamic-text-field-need-a-little-help/329569/1 "2012-09-16T00:52:30Z")

</div>

[COLOR=#333333]Hi there experienced AS3 fanatics![/COLOR]

[COLOR=#333333]This AS3 beginner is struggling with the following and asks for your help (and what is there in it for you, you ask?! RESPECT from my side [/COLOR] ![](http://www.republicofcode.com/forum/images/smilies/3.gif)[COLOR=#333333] :[/COLOR]

[COLOR=#333333]I have an XML with 350 nodes (geographical areas).[/COLOR]  
[COLOR=#333333]I have an text input field, where I want to fill in a number.[/COLOR]  
[COLOR=#333333]I have an dynamic text field where I want to show the corresponding node from the XML. [/COLOR]

[COLOR=#333333]At this moment I can fill in number “1” and the correct geographical area comes up in the dynamic text field.[/COLOR]

[COLOR=#333333]Here is my problem:[/COLOR]

[COLOR=#333333]How can I call the other 349 nodes, without creating a new VAR and a FUNCTION for every single node?[/COLOR]

[COLOR=#333333]My code so far is as follows:[/COLOR]

[COLOR=#333333]import flash.ui.Keyboard;[/COLOR]  
[COLOR=#333333]import flash.events.KeyboardEvent;[/COLOR]

[COLOR=#333333]var inputField:TextField = new TextField();[/COLOR]

[COLOR=#333333]addChild(inputField);[/COLOR]

[COLOR=#333333]inputField.border = true;[/COLOR]  
[COLOR=#333333]inputField.width = 27;[/COLOR]  
[COLOR=#333333]inputField.height = 20;[/COLOR]  
[COLOR=#333333]inputField.x = 112;[/COLOR]  
[COLOR=#333333]inputField.y = 10;[/COLOR]  
[COLOR=#333333]inputField.type = “input”;[/COLOR]  
[COLOR=#333333]inputField.maxChars = 3;[/COLOR]  
[COLOR=#333333]inputField.restrict = “1234567890”;[/COLOR]  
[COLOR=#333333]stage.focus = inputField;[/COLOR]

[COLOR=#333333]var outputField:TextField = new TextField();[/COLOR]

[COLOR=#333333]addChild(outputField);[/COLOR]

[COLOR=#333333]outputField.border = true;[/COLOR]  
[COLOR=#333333]outputField.width = 230;[/COLOR]  
[COLOR=#333333]outputField.height = 20;[/COLOR]  
[COLOR=#333333]outputField.x = 10;[/COLOR]  
[COLOR=#333333]outputField.y = 40;[/COLOR]  
[COLOR=#333333]outputField.type = “dynamic”;[/COLOR]

[COLOR=#333333]var xmlLoader:URLLoader = new URLLoader();[/COLOR]  
[COLOR=#333333]var xmlData:XML = new XML();[/COLOR]

[COLOR=#333333]xmlLoader.addEventListener(Event.COMPLETE, LoadXML);[/COLOR]

[COLOR=#333333]xmlLoader.load(new URLRequest(“prefix\_list.xml”));[/COLOR]

[COLOR=#333333]function LoadXML(e:Event):void {[/COLOR]  
[COLOR=#333333]xmlData = new XML(e.target.data);[/COLOR]  
[COLOR=#333333]for (var i:int = 0; i\<xmlData._.length(); i++){[/COLOR]  
[COLOR=#333333]trace("PREFIX " + (i+1) + ", COUNTRY " + xmlData.prefix\_list.country_);[/COLOR]  
[COLOR=#333333]};[/COLOR]  
[COLOR=#333333]}[/COLOR]

[COLOR=#333333]this.stage.addEventListener(KeyboardEvent.KEY\_DOWN , keyDownHandler);[/COLOR]

[COLOR=#333333]function keyDownHandler(event : KeyboardEvent):void {[/COLOR]  
[COLOR=#333333]if (event.keyCode == Keyboard.ENTER) {[/COLOR]

[COLOR=#333333]if (inputField.text == “1”) {[/COLOR]  
[COLOR=#333333]outputField.text = xmlData.prefix\_list.country[0];[/COLOR]  
[COLOR=#333333]} else {[/COLOR]  
[COLOR=#333333]outputField.text = xmlData.prefix\_list.country[351];[/COLOR]  
[COLOR=#333333]}[/COLOR]  
[COLOR=#333333]}[/COLOR]

[COLOR=#333333]}[/COLOR]

[COLOR=#333333]Thanks so much for your time and effort in trying to help me![/COLOR]

[COLOR=#333333]Best regards,[/COLOR]

[COLOR=#333333]James.[/COLOR]
