![]() |
|
||||||||||
|
|||||
|
Регистрация: Oct 2007
Сообщений: 20
|
Привет всем!
Подскажите пожалуйста как связать текстовое поле с XML файлом. Заранее спасибо. |
|
|||||
|
Регистрация: Dec 2006
Сообщений: 1,764
|
можно так, взято из примера в самом флеше:
//****************************************************************************
//Copyright (C) 2005 Macromedia, Inc. All Rights Reserved.
//The following is Sample Code and is subject to all restrictions on
//such code as contained in the End User License Agreement accompanying
//this product.
//****************************************************************************
/*
Working with XML Example - XML_languagePicker
This example shows you how to load, and parse XML and then manipulate it in Flash.
This example file loads XML data from an XML file that is in the same directory as the SWF file. You do NOT need to have an active Internet connection for this example to work. If you add languages to the XML file in the same format that the other languages use, then the combobox will display the new language.
*/
// Create an XML object
var languageXML:XML = new XML();
// After loading the XML from an external file (in the last line of the script)
// we'll store all the strings in an array of arrays.
// Each element of masterArray will be an array of
// language-specific strings.
// masterArray[0] contains our English strings
// masterArray[1] contains our French strings
// masterArray[2] contains our Simplified Chinese strings
var masterArray:Array = new Array();
// strip away white spaces in the XML file to prevent empty nodes from
// contaminating our master array
languageXML.ignoreWhite = true;
// This is the event handler for the onLoad event. This method will be called after
// all the XML is loaded by the load() command. We'll populate our master array here.
languageXML.onLoad = function(success) {
// move to first language node <strings><en>
var currentLangNode:XMLNode = this.firstChild.firstChild;
// Loop through the languages and place strings into separate language arrays
// The first element of each language array will be the name of the language
// which we'll use later to populate the lang_cb combobox.
// Variable i will be the index for langauge arrays in the master array
var i:Number = 0;
for (var childNode = currentLangNode; childNode != null; childNode = childNode.nextSibling, i++) {
// j will serve as the index for strings in each array
var j:Number = 0;
// create a new langauge array for each language
// e.g. masterArray[0] will be the first language array
masterArray[i] = new Array();
// place the node name (i.e. the language name) into element 0
// then increment j so that the first string will be stored in element 1
masterArray[i][0] = childNode.nodeName;
j++;
// loop through the strings in each language node
// adding each string as a new element in the language array
for (var stringNode:XMLNode = childNode.firstChild; stringNode != null; stringNode = stringNode.nextSibling, j++) {
masterArray[i][j] = stringNode.firstChild.nodeValue;
}
}
// Populate the combobox component with the language names
for (var k=0; k < masterArray.length; k++) {
lang_cb.addItem(masterArray[k][0]);
}
// Populate the initial value of the text fields on stage
welcome_txt.text = masterArray[0][1];
thanks_txt.text = masterArray[0][2];
}
////////////////
// Code for ComboBox
////////////////
// The ComboBox instance on the stage is named lang_cb
// The ComboBox is populated with the language names dynamically
// using the ComboBox.addItem() method in the languageXML.onLoad event handler
// Create a listener object that will listen for changes to the combobox
var langListener:Object = new Object();
// Define a function that will execute whenever the combobox changes
langListener.change = function (eventObj) {
for (var l=0; l < masterArray.length; l++) {
if (masterArray[l][0] == eventObj.target.value) {
welcome_txt.text = masterArray[l][1];
thanks_txt.text = masterArray[l][2];
prevent
break;
}
}
}
lang_cb.addEventListener("change", langListener);
languageXML.load("xml_languagePicker.xml");
|
|
|||||
|
Регистрация: Oct 2007
Сообщений: 20
|
Спасибки,но не очень понятно.
Ты не мог бы исходник кинуть. |
|
|||||
|
Регистрация: May 2003
Адрес: Tallinn
Сообщений: 3,182
|
а это что по-вашему?
|
|
|||||
|
Регистрация: Dec 2006
Сообщений: 1,764
|
а исходник лежит у тебя уже на машине, вот по такому примерно пути:
|
![]() |
![]() |
Часовой пояс GMT +4, время: 09:16. |
|
|
« Предыдущая тема | Следующая тема » |
|
|