PDA

View Full Version : setting button property to XML nodes


Navarone
10-08-2009, 05:15 PM
I am adding some XML nodes clip_mc to my box0 movieClip and I am not able to figure out how to give them button property.


//import the tweener class caurina
import caurina.transitions.Tweener;


//Set the "y" location on stage were the the first xml item will live
var yPlacement:int = 20;
//Set the "x" location on stage were all the xml items will line up
var xPlacement:int = 30;
//Set the distance each xml item will be seperated by
var distance:int = 15;

//Initialize the XML
//put xml file name into a string variable
//Initialize the URLRequest
//put URLRequest into a URLLoader
//myLoader listening for when the XML is complete
var myXML:XML = new XML();
var XML_URL:String = "myXML.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);


//Create xmlLoaded function
function xmlLoaded(event:Event):void{
//place the xml data into the myXML object
myXML= XML(myLoader.data);
//initialize and give var name to the new external XMLDocument
var xmlDoc:XMLDocument = new XMLDocument();
//Ingnore spacing around nodes(list items)
xmlDoc.ignoreWhite = true;
//Define a new name for the loaded XML that is the data in myLoader
var menuXML:XML = XML(myLoader.data);
//Parse the XML data into a readable format
xmlDoc.parseXML(menuXML.toXMLString());

// Run the "for each" loop to iterate throug all the menu items listed in the external XML file
for each(var ListItem:XML in myXML..ListItem){
//Access the value of the itemLabel node in our external XML file
var listLabel:String = ListItem.itemLabel.toString();

//set up text fields for the items in the menu
var myText1:TextField = new TextField();
myText1.text = listLabel;
myText1.autoSize = TextFieldAutoSize.LEFT;
myText1.x = 2;
myText1.y = 2;

//Create a movieClip holder for each menu item
var clip_mc = new MovieClip();
//add the menu item to the movie clip
clip_mc.addChild(myText1);
// add the new movieClip to the stage and stick in box0
box0.addChild(clip_mc);

// now position the movie clips inside box0
clip_mc.y = yPlacement;
clip_mc.x = xPlacement
//offset each one in the loop so they don't end up on top of on another
yPlacement = yPlacement + distance;

}
}


//set the text of the boxes at start up
box0.boxText.text = "Step 1";
box1.boxText.text = "Step 2";
box2.boxText.text = "Step 3";

//create event listeners for each box
box0.header.addEventListener(MouseEvent.CLICK, btnBox0, false, 0, true);
box1.header.addEventListener(MouseEvent.CLICK, btnBox1, false, 0, true);
box2.header.addEventListener(MouseEvent.CLICK, btnBox2, false, 0, true);

//set button mode to show hand cursor on rollover
box0.header.buttonMode = true;
box1.header.buttonMode = true;
box2.header.buttonMode = true;


//create functions to move boxes
function btnBox0(event:MouseEvent):void {
Tweener.addTween(box1,{y:250, time:1});
Tweener.addTween(box2,{y:275, time:1});
}

function btnBox1(event:MouseEvent):void {
Tweener.addTween(box1,{y:25, time:1});
Tweener.addTween(box2,{y:275, time:1});
}
function btnBox2(event:MouseEvent):void {
Tweener.addTween(box1,{y:25, time:1});
Tweener.addTween(box2,{y:50, time:1});
}