Dear everyone,
A couple of days ago I followed a tutorial that showed how to make a xml menu with as3 and ofc xml. My question is how can I load external swf’s in a container with using the xml buttons that I made.
AS3 Code:
//Imports needed for animation
import fl.transitions.Tween;
import fl.transitions.easing.*;
var xmlPath:String = "site.xml";
var settingsXML:XML;
var tweensArray:Array = new Array();
var buttonTween:Tween;
var loader = new URLLoader();
loader.load (new URLRequest(xmlPath));
loader.addEventListener (Event.COMPLETE, xmlLoaded);
//This function is called when the XML file is loaded
function xmlLoaded (e:Event):void {
//Make sure we're not working with a null loader
if ((e.target as URLLoader) != null ) {
//Insert the loaded data to our XML variable
settingsXML = new XML(loader.data);
settingsXML.ignoreWhitespace = true;
//Call the function that creates the whole menu
createMenu ();
}
}
function createMenu ():void {
//This will be used to represent a menu item
var menuItem:MenuItem;
//Counter
var i:uint = 0;
//Loop through the links found in the XML file
for each (var link:XML in settingsXML.links.link) {
menuItem = new MenuItem();
//Insert the menu text (link.@name reads the link's "name" attribute)
menuItem.menuLabel.text = link.@name;
//If the text is longer than the textfield, autosize so that the text is
//treated as left-justified text
menuItem.menuLabel.autoSize = TextFieldAutoSize.LEFT;
//Insert the menu button to stage
menuItem.x = 0;
menuItem.y = 4 + i*60;
//Make the button look like a button (hand cursor)
menuItem.buttonMode = true;
menuItem.mouseChildren = false;
//Add event handlers (used for animating the buttons)
menuItem.addEventListener (MouseEvent.MOUSE_OVER, mouseOverHandler);
menuItem.addEventListener (MouseEvent.MOUSE_OUT, mouseOutHandler);
addChild (menuItem);
//Increment the menu button counter, so we know how many buttons there are
i++;
}
}
//Function is called when the mouse is over a menu button
function mouseOverHandler (e:Event):void {
//Double the width
buttonTween = new Tween(e.target, "scaleX", Elastic.easeOut, 1, 2, 1, true);
}
//Function is called when the mouse moves out from the menu button
function mouseOutHandler (e:Event):void {
//Tween back original scale
buttonTween = new Tween(e.target, "scaleX", Elastic.easeOut, e.target.scaleX, 1, 1, true);
}
Xml Code:
<?xml version="1.0" encoding="UTF-8"?>
<site>
<links>
<link name="Home"/>
<link name="About"/>
<link name="Work"/>
<link name="Contact"/>
</links>
</site>
I hope that someone can help me with this problem.