Hi,
This code shows you how to create a button to change its label via xml.
1.You need to create a new movie clip! The name is up to you.
2. Draw the button shape.
3. Add a new layer called "Text".
4. Add a dynamic textbox called "btText" to the "Text" layer.
5. Go back to the main stage add a new layer called "Actions" and add the following code:
6. Create an xml file called "menuDef.xml" and add the following text to it:Code:var link: URLRequest = new URLRequest("menuDef.xml"); var loader:URLLoader = new URLLoader(link); var i:int var myXML:XML = new XML(); //call the loaders load function to load the specified URL loader.load(link); loader.addEventListener(Event.COMPLETE,dataLoaded); //Button code function dataLoaded (event: Event){ myXML = new XML(loader.data); for (i = 0; i < 6; i++){ var j:int = i+ 1; /**0 is the line in the xml the labels start from. (i) starts counting from the 0 line until the end specified above.**/ this["btnEnter"].btText.text = myXML.child(0).child(0); } }
7. Go back to flash and add another layer called "content".<?xml version="1.0"?>
<menu>
<menuLabels>
<label>Home</label>
</menuLabels>
</menu>
8. Drag the newly created movie clip onto the "content" layer (stage) and put "btnEnter" as the instants name.
9. Run the project.
Nightwalker


Reply With Quote
