mahoganyhorizons
07-25-2006, 10:18 PM
Hello everyone. This is my first time using this forum. This is a bit of code I have stolen from kirupa.com and modified for my own purposes.
It was originally a simple xml menu, and I modified it so that it loads videos, sounds, and flash movies dynamically.
I need some help with another function I would like to build, and I was wondering if a more experienced developer could offer assitance.
I want to add forward and back buttons so that I can navigate between individual sub menus, I think using the nextSibling property.
Basically it would mean that
If I had this in my xml file
<menu name="Discussions"mouseAction="OnRollOver" mouseDisplay="Lesson 2: Listening Assignment from Discussions:">
<item name="Soprano" action="playSoundFile" variables="Lesson2/Listening Assignment From Discussions/female voices/soprano/12 Gianni Schicchi, opera- O mio babbino caro.mp3" mouseAction="OnRollOver" mouseDisplay="Soprano: Gianni Schicchi, opera- O mio babbino caro" />
<item name="Mezzo Soprano" action="playSoundFile" variables="Lesson2/Listening Assignment From Discussions/female voices/mezzo soprano/07 Semele, oratorio, HWV 58- Hence, Iris, hence away.mp3" mouseAction="OnRollOver" mouseDisplay="Mezzo Soprano: Semele, oratorio, HWV 58- Hence, Iris, hence away" />
<item name="Contralto 1" action="playSoundFile" variables="lesson2/Listening Assignment From Discussions/female voices/contralto/01 Serse, opera, HWV 40- Frondi tenere...Ombra mai fu.mp3" mouseAction="OnRollOver" mouseDisplay="Contralto 1: Serse (Xerxes), opera, HWV 40- Frondi tenere...Ombra mai fu " />
<item name="Contralto 2" action="playSoundFile" variables="lesson2/Listening Assignment From Discussions/female voices/contralto/02 Serse, opera, HWV 40- Frondi tenere...Ombra mai fu.mp3" mouseAction="OnRollOver" mouseDisplay="Contralto 2: Serse (Xerxes), opera, HWV 40- Frondi tenere...Ombra mai fu 2" />
<item name="Tenor" action="playSoundFile" variables="lesson2/Listening Assignment From Discussions/female voices/tenor/13 Turandot, opera- Nessun dorma (Comp. by Alfano).mp3" mouseAction="OnRollOver" mouseDisplay="Tenor: Turandot, opera- Nessun dorma (Comp. by Alfano)" />
<item name="Base" action="playSoundFile" variables="lesson2/Listening Assignment From Discussions/female voices/bass/14 Ol' Man River.mp3" mouseAction="OnRollOver" mouseDisplay="Base: Ol' Man River" />
</menu>
I could navigate through all the items in the discussion area. Thanks in advance for any help given!!
Here is the actionscript I modified from kirupa.com
// 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) {
// 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);
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[i];
//curr_item.sibling= node_xml.childNodes[i].nextSibling.attributes.action;
//node_xml.childNodes[i].nextSibling;
curr_item.action = curr_node.attributes.action;
curr_item.variables = curr_node.attributes.variables;
curr_item.mouseAction = curr_node.attributes.mouseAction;
curr_item.mouseDisplay = curr_node.attributes.mouseDisplay;
curr_item.mediaAction = curr_node.attributes.mediaAction;
curr_item.mediaController = curr_node.attributes.mediaController;
curr_item.titleAction= curr_node.attributes.titleAction;
curr_item.titleDisplay= curr_node.attributes.titleDisplay;
curr_item.name.text = curr_node.attributes.name;
//curr_item.sibiling= node_xml.childNodes[i].nextSibling;
// item submenu behavior for rollover event
//trace(node_xml.childNodes[i].nextSibling);
//trace(node_xml.childNodes[i]);
trace(node_xml.childNodes[i].nodeName);
if (node_xml.childNodes[i].nodeName == "menu"){
// open a submenu
curr_item.node_xml = curr_node;
curr_item.onRollOver = curr_item.onDragOver = function(){
var x = this._x + this._width - 5;
var y = this._y + 5;
GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml);
// show a hover color
var col = new Color(this.background);
col.setRGB(0xf4faff);
//This sets a custom Mouse Action Event, and is needed to enable rollover
//actions on a main menu
mouseAction[this.mouseAction](this.mouseDisplay);
//sets a coustom titleAction Class for Title Rollover events
//needs to be seperate so you can have a seprate Rollover, and Title class
titleAction[this.titleAction](this.titleDisplay);
};
}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(0xf4faff);
//sets a custom mouseAction Class For Rollover events
mouseAction[this.mouseAction](this.mouseDisplay);
//sets a coustom titleAction Class for Title Rollover events
//needs to be seperate so you can have a seprate Rollover, and Title class
titleAction[this.titleAction](this.titleDisplay);
};
}
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,b b:0});
};
// any item, menu opening or not can have actions
// this is also expandable, and additional custom classes
// can be created here that utilize various attributes
curr_item.onRelease = function(){
Actions[this.action](this.variables);
mediaAction[this.mediaAction](this.mediaController);
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);
// 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();
};
//closes all flash movies displayed in the movie clip
//when the mouse is moved anywhere over the menu
//this eliminates the movie being displayed after the user is done
//viewing it.
//This is called in the mouse action rollover event class.
CloseLoadedSWF = function() {
//Close Movie Clip loaded in the CloseLoaded SWF function that loads
//a clip directly into a level.
unloadMovie("_level1");
loadMovie_mc.unloadMovie();
}
//Closes the sound controls for audio files when the mouse is movied
//anywhere over the menu.
//This eliminates the sound controls being displayed after the user
//wants to switch to another file.
//This is called in the mouse action rollover event class.
CloseSoundControls= function() {
unloadMovie("volumedown_mc");
unloadMovie("volumeup_mc");
unloadMovie("stopsound_mc");
unloadMovie("playsound_mc");
}
//Closes the video controls for the video files when the mouse is moved
//anywhere over the menu
//This eliminates the video controls being displayed after the user
//wants to switch to another file.
//This is called in the mouse action rollover event class.
CloseVideoControls= function() {
unloadMovie("ffvideo_mc");
unloadMovie("stopvideo_mc");
unloadMovie("playvideo_mc");
unloadMovie("rewvideo_mc");
}
//Stop any music that is loaded when the mouse is moved over the menu
//This action indicates that the user wants to move to a new sound file
//so music should be stopped
//Again classed by the ouse Action rollover event class.
StopMusic= function() {
music.stop();
}
ClearVid= function() {
//To close a playing video
//Close the Video Stream
test_ns.close();
//Close the Video
vidHolder.close();
//Clear the Video
vidHolder.clear();
//Unload the Video from the movie clip
vidHolder.unloadMovie();
}
ClearTitleText= function() {
//There is no function to automatically clear text in flash.
//Clear the text by setting text field to an empty string.
//Focus the field
title_txt.text="";
}
// 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");
};
//Action to load an external.swf in the movie
//LoadSWF is the attribute in the xml file that is
//used to tell the movie that it needs to load a flash movie
//loadMovieVar is a variable that was created
//to represent the value of the variable field in the xml file
Actions.LoadSWF = function(loadMovieVar){
//Uncomment to load movie from a level directly into the movie, in a depth level
//and NOT into a movie clip
loadMovie(loadMovieVar, "_level1");
}
//End Code Part I
It was originally a simple xml menu, and I modified it so that it loads videos, sounds, and flash movies dynamically.
I need some help with another function I would like to build, and I was wondering if a more experienced developer could offer assitance.
I want to add forward and back buttons so that I can navigate between individual sub menus, I think using the nextSibling property.
Basically it would mean that
If I had this in my xml file
<menu name="Discussions"mouseAction="OnRollOver" mouseDisplay="Lesson 2: Listening Assignment from Discussions:">
<item name="Soprano" action="playSoundFile" variables="Lesson2/Listening Assignment From Discussions/female voices/soprano/12 Gianni Schicchi, opera- O mio babbino caro.mp3" mouseAction="OnRollOver" mouseDisplay="Soprano: Gianni Schicchi, opera- O mio babbino caro" />
<item name="Mezzo Soprano" action="playSoundFile" variables="Lesson2/Listening Assignment From Discussions/female voices/mezzo soprano/07 Semele, oratorio, HWV 58- Hence, Iris, hence away.mp3" mouseAction="OnRollOver" mouseDisplay="Mezzo Soprano: Semele, oratorio, HWV 58- Hence, Iris, hence away" />
<item name="Contralto 1" action="playSoundFile" variables="lesson2/Listening Assignment From Discussions/female voices/contralto/01 Serse, opera, HWV 40- Frondi tenere...Ombra mai fu.mp3" mouseAction="OnRollOver" mouseDisplay="Contralto 1: Serse (Xerxes), opera, HWV 40- Frondi tenere...Ombra mai fu " />
<item name="Contralto 2" action="playSoundFile" variables="lesson2/Listening Assignment From Discussions/female voices/contralto/02 Serse, opera, HWV 40- Frondi tenere...Ombra mai fu.mp3" mouseAction="OnRollOver" mouseDisplay="Contralto 2: Serse (Xerxes), opera, HWV 40- Frondi tenere...Ombra mai fu 2" />
<item name="Tenor" action="playSoundFile" variables="lesson2/Listening Assignment From Discussions/female voices/tenor/13 Turandot, opera- Nessun dorma (Comp. by Alfano).mp3" mouseAction="OnRollOver" mouseDisplay="Tenor: Turandot, opera- Nessun dorma (Comp. by Alfano)" />
<item name="Base" action="playSoundFile" variables="lesson2/Listening Assignment From Discussions/female voices/bass/14 Ol' Man River.mp3" mouseAction="OnRollOver" mouseDisplay="Base: Ol' Man River" />
</menu>
I could navigate through all the items in the discussion area. Thanks in advance for any help given!!
Here is the actionscript I modified from kirupa.com
// 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) {
// 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);
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[i];
//curr_item.sibling= node_xml.childNodes[i].nextSibling.attributes.action;
//node_xml.childNodes[i].nextSibling;
curr_item.action = curr_node.attributes.action;
curr_item.variables = curr_node.attributes.variables;
curr_item.mouseAction = curr_node.attributes.mouseAction;
curr_item.mouseDisplay = curr_node.attributes.mouseDisplay;
curr_item.mediaAction = curr_node.attributes.mediaAction;
curr_item.mediaController = curr_node.attributes.mediaController;
curr_item.titleAction= curr_node.attributes.titleAction;
curr_item.titleDisplay= curr_node.attributes.titleDisplay;
curr_item.name.text = curr_node.attributes.name;
//curr_item.sibiling= node_xml.childNodes[i].nextSibling;
// item submenu behavior for rollover event
//trace(node_xml.childNodes[i].nextSibling);
//trace(node_xml.childNodes[i]);
trace(node_xml.childNodes[i].nodeName);
if (node_xml.childNodes[i].nodeName == "menu"){
// open a submenu
curr_item.node_xml = curr_node;
curr_item.onRollOver = curr_item.onDragOver = function(){
var x = this._x + this._width - 5;
var y = this._y + 5;
GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml);
// show a hover color
var col = new Color(this.background);
col.setRGB(0xf4faff);
//This sets a custom Mouse Action Event, and is needed to enable rollover
//actions on a main menu
mouseAction[this.mouseAction](this.mouseDisplay);
//sets a coustom titleAction Class for Title Rollover events
//needs to be seperate so you can have a seprate Rollover, and Title class
titleAction[this.titleAction](this.titleDisplay);
};
}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(0xf4faff);
//sets a custom mouseAction Class For Rollover events
mouseAction[this.mouseAction](this.mouseDisplay);
//sets a coustom titleAction Class for Title Rollover events
//needs to be seperate so you can have a seprate Rollover, and Title class
titleAction[this.titleAction](this.titleDisplay);
};
}
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,b b:0});
};
// any item, menu opening or not can have actions
// this is also expandable, and additional custom classes
// can be created here that utilize various attributes
curr_item.onRelease = function(){
Actions[this.action](this.variables);
mediaAction[this.mediaAction](this.mediaController);
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);
// 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();
};
//closes all flash movies displayed in the movie clip
//when the mouse is moved anywhere over the menu
//this eliminates the movie being displayed after the user is done
//viewing it.
//This is called in the mouse action rollover event class.
CloseLoadedSWF = function() {
//Close Movie Clip loaded in the CloseLoaded SWF function that loads
//a clip directly into a level.
unloadMovie("_level1");
loadMovie_mc.unloadMovie();
}
//Closes the sound controls for audio files when the mouse is movied
//anywhere over the menu.
//This eliminates the sound controls being displayed after the user
//wants to switch to another file.
//This is called in the mouse action rollover event class.
CloseSoundControls= function() {
unloadMovie("volumedown_mc");
unloadMovie("volumeup_mc");
unloadMovie("stopsound_mc");
unloadMovie("playsound_mc");
}
//Closes the video controls for the video files when the mouse is moved
//anywhere over the menu
//This eliminates the video controls being displayed after the user
//wants to switch to another file.
//This is called in the mouse action rollover event class.
CloseVideoControls= function() {
unloadMovie("ffvideo_mc");
unloadMovie("stopvideo_mc");
unloadMovie("playvideo_mc");
unloadMovie("rewvideo_mc");
}
//Stop any music that is loaded when the mouse is moved over the menu
//This action indicates that the user wants to move to a new sound file
//so music should be stopped
//Again classed by the ouse Action rollover event class.
StopMusic= function() {
music.stop();
}
ClearVid= function() {
//To close a playing video
//Close the Video Stream
test_ns.close();
//Close the Video
vidHolder.close();
//Clear the Video
vidHolder.clear();
//Unload the Video from the movie clip
vidHolder.unloadMovie();
}
ClearTitleText= function() {
//There is no function to automatically clear text in flash.
//Clear the text by setting text field to an empty string.
//Focus the field
title_txt.text="";
}
// 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");
};
//Action to load an external.swf in the movie
//LoadSWF is the attribute in the xml file that is
//used to tell the movie that it needs to load a flash movie
//loadMovieVar is a variable that was created
//to represent the value of the variable field in the xml file
Actions.LoadSWF = function(loadMovieVar){
//Uncomment to load movie from a level directly into the movie, in a depth level
//and NOT into a movie clip
loadMovie(loadMovieVar, "_level1");
}
//End Code Part I