Hi guys,
Im trying new website with the help of AS3 with XML.
I cannot merge 2 AS3 files into single file. Both as3 contains XML files. If i added multiple layers for each as3 it shows lot of errors … Here is my code plz help me to clear this.
MENU.fla
// generates a list of menu items (effectively one menu)
// given the inputted parameters. This makes the main menu
// as well as any of the submenus
GenerateMenu = function(container, name, x, y, depth, node_xml, vertical) {
// variable declarations
var curr_node;
var curr_item;
var curr_menu = container.createEmptyMovieClip(name, depth);
// for all items or XML nodes (items and menus)
// within this node_xml passed for this menu
for (var i=0; i<node_xml.childNodes.length; i++) {
// movieclip for each menu item
curr_item = curr_menu.attachMovie("menuitem","item"+i+"_mc", i);
if(vertical)
{
curr_item._x = x+ i*curr_item._width;
curr_item._y = y ;
}else
{
curr_item._x = x;
curr_item._y = y+ i*curr_item._height ;
}
curr_item.trackAsMenu = true;
// item properties assigned from XML
curr_node = node_xml.childNodes*;
curr_item.action = curr_node.attributes.action;
curr_item.variables = curr_node.attributes.variables;
curr_item.name.text = curr_node.attributes.name;
// item submenu behavior for rollover event
if (node_xml.childNodes*.nodeName == "menu"){
// open a submenu
curr_item.node_xml = curr_node;
curr_item.onRollOver = curr_item.onDragOver = function(){
var x = this._x;
var y = this._y - 95;
GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml,false);
// show a hover color
var col = new Color(this.background);
col.setRGB(0x000);
};
}else{ // nodeName == "item"
curr_item.arrow._visible = false;
// close existing submenu
curr_item.onRollOver = curr_item.onDragOver = function(){
curr_menu.submenu_mc.removeMovieClip();
// show a hover color
var col = new Color(this.background);
col.setRGB(0x000);
};
}
curr_item.onRollOut = curr_item.onDragOut = function(){
// restore color
var col = new Color(this.background);
col.setTransform({ra:100,rb:0,ga:100,gb:0,ba:100,bb:0});
};
// any item, menu opening or not can have actions
curr_item.onRelease = function(){
Actions[this.action](this.variables);
CloseSubmenus();
};
} // end for loop
};
// create the main menu, this will be constantly visible
CreateMainMenu = function(x, y, depth, menu_xml){
// generate a menu list
GenerateMenu(this, “mainmenu_mc”, x, y, depth, menu_xml.firstChild,true);
// close only submenus if visible durring a mouseup
// this main menu (mainmenu_mc) will remain
mainmenu_mc.onMouseUp = function(){
if (mainmenu_mc.submenu_mc && !mainmenu_mc.hitTest(_root._xmouse, _root._ymouse, true)){
CloseSubmenus();
}
};
};
// closes all submenus by removing the submenu_mc
// in the main menu (if it exists)
CloseSubmenus = function(){
mainmenu_mc.submenu_mc.removeMovieClip();
};
// This actions object handles methods for actions
// defined by the XML called when a menu item is pressed
Actions = Object();
Actions.gotoURL = function(urlVar){
getURL(urlVar, “_blank”);
};
Actions.message = function(msg){
message_txt.text = msg;
};
Actions.newMenu = function(menuxml){
menu_xml.load(menuxml);
};
// load XML, when done, run CreateMainMenu to interpret it
menu_xml = new XML();
menu_xml.ignoreWhite = true;
menu_xml.onLoad = function(ok){
// create main menu after successful loading of XML
if (ok){
CreateMainMenu(100, 600, 0, this);
message_txt.text = “message area”;
}else{
message_txt.text = “error: XML not successfully loaded”;
}
};
// load first XML menu
menu_xml.load(“menu1.xml”);
[HR][/HR]
Menu1.xml
<menu name=“example”>
<item name="Our Philosophy" />
<item name="About" />
<menu name="Projects">
<item name="Proposed Project"/>
<item name="Ongoing Project"/>
<item name="Completed Project"/>
</menu>
<item name="Key People"/>
<item name="Testimonials"/>
<item name="Contact Us"/>
</menu>
[HR][/HR]
slideshow.fla
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Loader;
import flash.utils.Timer;
import flash.events.TimerEvent;
import fl.transitions.;
import fl.transitions.easing.;
import flash.events.MouseEvent;
///*************************************************************///
// declare variables
var xmlData:XML;
var xmlLoader:URLLoader = new URLLoader();
var picLoader:Loader = new Loader();
var picArray:Array = new Array();
var titleArray:Array = new Array();
var numberOfPics:int;
var currentPic:Number =0;
var myMusicClip:String;
var delay:Number;
///*************************************************************///
//Process XML Data
xmlLoader.load(new URLRequest(“slideshow.xml”));
xmlLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(event:Event):void{
xmlData = new XML(event.target.data);
/*trace(xmlData);*/
numberOfPics=xmlData.photolist.photo.length();
delay=xmlData.timer.text();
loadArrays();
loadImages();
function loadArrays()
{
for (var i:int=0; i<numberOfPics ; i++)
{
picArray.push(xmlData.photolist.photo*.@path);
titleArray.push(xmlData.photolist.photo*.@title);
}
}
///*************************************************************///
// load images
function loadImages(){
var myURLRequest:URLRequest = new URLRequest(picArray[currentPic]);
picLoader.load(myURLRequest);
picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completehandler)
}
///*************************************************************///
// display loaded Images
function completehandler(event:Event)
{
addChildAt(picLoader,0);
picLoader.x=6;
picLoader.y = 4.5;
}
var myTimer:Timer = new Timer(delay);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, changeImage);
function changeImage(event:TimerEvent)
{
if(currentPic<numberOfPics-1){currentPic++;loadImages()}
else{currentPic=0;loadImages()}
}
}
[HR][/HR]
slideshow.xml
<?xml version=“1.0” encoding=“utf-8”?>
<slideshow>
<photolist>
<photo path=“images/image1.jpg” title=“Barbecued Chicken” />
<photo path=“images/image2.jpg” title=“Bread and Rolls” />
</photolist>
<audio>
<musicclip path="audio/soothing_music.mp3"/>
</audio>
<timer>4000</timer>
</slideshow>
[HR][/HR]Please help to combine this,