Good morning,
I am working on a dynamic menu for a client. This is my first time creating a menu loaded from an xml file. I have the basics down, but am hitting a brick wall. I will have six buttons that are attached at run time, and will be labeled according to the button names in the xml file. Eventually these buttons will be rotating in a circle, but I’m just testing the functionality at the moment. I tried searching through the forum, and didn’t find anything that resembled what I am trying to do. To start off here is the xml file:
[COLOR=#008080]<?xml version=“1.0” encoding=“UTF-8”?>
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]menu[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#ff0000] buttonName[/COLOR][COLOR=#0000ff]="[/COLOR]Home[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#ff0000] contentTitle[/COLOR][COLOR=#0000ff]="[/COLOR]Home[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<![CDATA[[/COLOR]This is the content for the Home Button[COLOR=#0000ff]]]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#ff0000] buttonName[/COLOR][COLOR=#0000ff]="[/COLOR]About[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#ff0000] contentTitle[/COLOR][COLOR=#0000ff]="[/COLOR]About[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<![CDATA[[/COLOR]This is the content for the About Button[COLOR=#0000ff]]]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#ff0000] buttonName[/COLOR][COLOR=#0000ff]="[/COLOR]Services[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#ff0000] contentTitle[/COLOR][COLOR=#0000ff]="[/COLOR]Services[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<![CDATA[[/COLOR]This is the content for the Services Button[COLOR=#0000ff]]]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#ff0000] buttonName[/COLOR][COLOR=#0000ff]="[/COLOR]Portfolio[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#ff0000] contentTitle[/COLOR][COLOR=#0000ff]="[/COLOR]Portfolio[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<![CDATA[[/COLOR]This is the content for the Portfolio Button[COLOR=#0000ff]]]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#ff0000] buttonName[/COLOR][COLOR=#0000ff]="[/COLOR]Products[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#ff0000] contentTitle[/COLOR][COLOR=#0000ff]="[/COLOR]Products[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<![CDATA[[/COLOR]This is the content for the Products Button[COLOR=#0000ff]]]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#ff0000] buttonName[/COLOR][COLOR=#0000ff]="[/COLOR]Contact Us[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#ff0000] contentTitle[/COLOR][COLOR=#0000ff]="[/COLOR]Contact Us[COLOR=#0000ff]">
[/COLOR][COLOR=#0000ff]<![CDATA[[/COLOR]This is the content for the Contact Us Button[COLOR=#0000ff]]]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]content[/COLOR][COLOR=#0000ff]>
[/COLOR][COLOR=#0000ff]</[/COLOR][COLOR=#800000]button[/COLOR][COLOR=#0000ff]>
</[/COLOR][COLOR=#800000]menu[/COLOR][COLOR=#0000ff]>[/COLOR]
[COLOR=#0000ff][COLOR=#000000]As you can see there will be six buttons labeled from the buttonName Attributes. Here is the actionscript I have to load the xml file, and loop through the button elements, and then loop to attach 6 buttons, and try to label them by the button element attributes:[/COLOR][/COLOR]
“Flash 8 Professional, Actionscript 2.0”
[COLOR=#0000ff][COLOR=#000000]var RootNode:XMLNode;[/COLOR][/COLOR]
var xPos:Number = 10;
var yPos:Number = 10;
[COLOR=#0000ff][COLOR=#000000]var menuXML:XML = new XML();
menuXML.ignoreWhite = true;
menuXML.onLoad=loadContent;
menuXML.load(“testMenu.xml”);
stop();[/COLOR][/COLOR]
[COLOR=#0000ff][COLOR=#000000]function loadContent(success:Boolean):Void{
if (success) {
RootNode = this.firstChild;
loadButton();
}
else {
trace(“Error in loading XML file”);
}
}[/COLOR][/COLOR]
[COLOR=#0000ff][COLOR=#000000]
function loadButton():Void {
var buttonName:String;
for (var i:Number = 0; i<RootNode.childNodes.length; i++) {
buttonName = RootNode.childNodes*.attributes.buttonName;
trace(buttonName);
}
for (var m:Number = 0; m<6; m++) {
this.attachMovie(“mcButton”, “mcButton”+m, m, {_x:xPos, _y:yPos});
yPos += this[“mcButton”+m]._height+5;
mcButton[m].buttonText.text = buttonName;
trace(mcButton[m].buttonText.text);
}
}
When I test this movie the output window shows this:
Home
About
Services
Portfolio
Products
Contact Us
undefined
undefined
undefined
undefined
undefined
undefined
I have been able to trace the attribute names from the xml file, but textbox’s from the dynamic buttons are not being labeled. They are coming up undefined. I’m having a brain fart on this. Can anyone point me in the right direction? Greatly appreciated in advance.
Thank you,
Jason[/COLOR]
P.S. This is the flow of how this project will take place:
[LIST]
[][FONT=Arial]Load external xml file into Flash.[/FONT]
[][FONT=Arial]Loop through elements to define the button label names.[/FONT]
[][FONT=Arial]Create a loop to attach a movieClip at run time into a holder clip named “mcCircle”.[/FONT]
[][FONT=Arial]Label the dynamic text field in each new movieClip with the label names from the xml file.[/FONT]
[][FONT=Arial]Arrange the movieClips on the stage in a circle movieClip.[/FONT]
[][FONT=Arial]Rotate the circle movieClip clockwise using trig: sine and cosine. [/FONT]
[][FONT=Arial]Set a speed and velocity variable to the circle movieClip[/FONT]
[][FONT=Arial]When the mouse moves Over a button, have the circle movieClip slow down it’s speed to a stop.[/FONT]
[][FONT=Arial]When the mouse moves Out of a button, have the circle movieClip speed up to it’s normal rotation speed.[/FONT]
[][FONT=Arial]When the mouse clicks on a button, have the circle movieClip shrink down and move to the lower right corner of the stage.[/FONT]
[][FONT=Arial]Tell Flash to load the content from the xml file (of the button label clicked) to a dynamic textfield on the stage. [/FONT]
[][FONT=Arial]When the user is done reading the content they will click on a button to clear the text field, and bring the menu back to center, and original size.[/FONT][/LIST][/COLOR]