PDA

View Full Version : XML nodes--forward and back buttons, or next sibling, actionscript and xml.


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

mahoganyhorizons
07-25-2006, 10:20 PM
//Code Part 2

//Action used to play a soundfile in the movie
Actions.playSoundFile = function(loadSoundVar){

music= new Sound();

//needs the true or the projector won't know how to load the mp3 file

music.loadSound(loadSoundVar, true);
music.onLoad = function(){
music.setVolume (100);
this.start();
}

//Set Max Volume for Button, Min Volume for Button, and Volume Increment for button
var maxVolume= 200;
var minVolume= 0;
var volumeIncrement= 20;
//Load the volume up Symbol from the symbols Library
//Load it dynamically so that it will only be seen when user
//is using a soundfile.
//Note that you must set the export options to export for actionscript
//and you must type a name in the identifier field.
//For this particular movie, you must use the root, to get
//this function to work, because you don't know where this
//clip will appear in the nested hiearchy because of all the
//xml menus.

//Create dynamic button instance to control volume down
_root.attachMovie("volumeDownSymbol", "volumedown_mc",1);

//Create dynamic button instance to control volume up
//The volume down button is #1 in the stacking order so you have
//to put this at number 2
_root.attachMovie("volumeUpSymbol", "volumeup_mc",2);

//Create dynamic button instance to stop sound
//The volume down button is #1 in the stacking order so you have
//volume up is #2, so you have to put this at #3 in the stacking order.
_root.attachMovie("stopSoundSymbol", "stopsound_mc",3);

//Create Dynamic button instance to play sound
//layer 4 in stacking order

_root.attachMovie("playSoundSymbol", "playsound_mc",4);

//position Down button on the stage
volumedown_mc._x=210
volumedown_mc._y=375

//position Up button on the stage
volumeup_mc._x=470
volumeup_mc._y=375

//position stop button on the stage

stopsound_mc._x=285
stopsound_mc._y=375

//position play button on the stage

playsound_mc._x=380
playsound_mc._y=375

//Create an on release Action for Volume Down button, that adjusts the volume level

_root.volumedown_mc.onRelease = function() {

music.setVolume(Math.max(music.getVolume() - volumeIncrement, minVolume));

}

//Create an on release Action for Volume Up button, that adjusts the volume level

_root.volumeup_mc.onRelease = function() {

music.setVolume(Math.min(music.getVolume() + volumeIncrement, maxVolume));

}

//Create an on release Action for stop sound button, that stops the sound

_root.stopsound_mc.onRelease = function() {

music.stop();




}

//Create an on release Action for play button, that stops the sound

_root.playsound_mc.onRelease = function() {

music.start();


}

} //end sound play file action

Actions.message = function(msg){
message_txt.text = msg;
};
Actions.newMenu = function(menuxml){
menu_xml.load(menuxml);
};

mediaAction = Object();
mediaAction.flashShow = function(loadMediaControllerVar)
{
//loadMovie(loadMediaControllerVar, "_level5");

//Create an empty movie clip called loadMovieSymbol to load the movie in
//Name it loadMovie, MC
//Set it with a depth level of 20
//This gives you more control over the movie and its placement
//Allowing you to place the movieclip on the stage by x and y coorinates

_root.attachMovie("loadMovieSymbol", "loadMovie_mc",20);

//Position movie clip on screen

loadMovie_mc._x =175;
loadMovie_mc._y =25;

//Load the movieclip with the variable name contained in the xml file
//into loadMovie_mc

loadMovie_mc.loadMovie(loadMediaControllerVar,"loa dMovie_mc");


}

mediaAction.videoShow = function(loadvideoControllerVar){
//Set Net Connection
test_nc = new NetConnection();
test_nc.connect(null);
//Set Net Stream
test_ns = new NetStream(test_nc);
//create empty movie clip for movie
thisMovie = this.createEmptyMovieClip("thisMovie", 1);
//attach movie to this movie videoclip, where they symbol is called
//videoHolder_mc, and name video instance vidHolder
myVideo = thisMovie.attachMovie("videoHolder_mc", "vidHolder", 1);
vidHolder.attachVideo(test_ns);
//VideoClip has a size of 1 pixle by 1 pixle to keep it hidden
//on screen and out of the way, since it has to be shown dynamically
//Size movie clip that contains video holder on screen dynamically
//These are commented out for the bonnie CD project,
//because it distorts the PowerPoint files that are used
//to create the videos.
//vidHolder._xscale= 320;
//vidHolder._yscale= 240;
//vidHolder._xscale= 320;
//vidHolder._yscale= 216;
//Position movie clip that contains video holder on Screen Dynamically
//vidHolder._x= 200;
//vidHolder._y= 70;

//vidHolder._x= 170;
//vidHolder._y= 10;

//Play Video Clip
test_ns.play(loadvideoControllerVar);
//Create dynamic button instance to control video fast forward
_root.attachMovie("ffVidSymbol", "ffvideo_mc",1);
//Create dynamic button instance to control video stop
_root.attachMovie("stopVideoSymbol", "stopvideo_mc",2);
//Create dynamic button instance to control video play
_root.attachMovie("playVideoSymbol", "playvideo_mc",3);

//Create dynamic button instance to control video rewind
_root.attachMovie("rewVidSymbol", "rewvideo_mc",4);


//position ffbutton button on the stage
ffvideo_mc._x=210;
ffvideo_mc._y=415;

//position stop video button on the stage

stopvideo_mc._x=310;
stopvideo_mc._y=415;

//position play video button on stage

playvideo_mc._x=410;
playvideo_mc._y=415;

//position rewbutton button on the stage
rewvideo_mc._x=510;
rewvideo_mc._y=415;


//Create an on release Action for ff button, that controls ff


_root.ffvideo_mc.onRelease = function() {


//use the seek command to move forward
//three seconds in the video
//from the current time, using the test_ns.time function

test_ns.seek(test_ns.time + 3);

};


//Create an on release Action for rew button, that controls rew

_root.rewvideo_mc.onRelease = function() {

//use the seek command to move backward
//three seconds in the video
//from the current time, using the test_ns.time function


test_ns.seek(test_ns.time - 3);


};

//Create on Release Action for stop button to stop movie

_root.stopvideo_mc.onRelease = function() {

//use the pause command to stop video streaming playback.
test_ns.pause();

};

//Create on Release Action for play button to stop movie

_root.playvideo_mc.onRelease = function() {

//use the pause command to stop video streaming playback.
test_ns.pause();

};
}

mediaAction.gotoURL = function(urlVar){
getURL(urlVar, "_blank");
};

mouseAction = Object();
mouseAction.OnRollOver = function(mouseDisplayVar) {

message_txt.text= mouseDisplayVar;

titleAction = Object();
titleAction.rollTitle = function(rollTitleVar) {
title_txt.text= rollTitleVar;
}

//If an swf is loaded, close it.
//This will always closee any flash movie that is open because it is
//detecting the mouseover event.

CloseLoadedSWF();
//If sound controls are loaded, close them, this will close any sound
//controls that are open because it is dectecting the mouseover event.
CloseSoundControls();
//If music is loaded, then close the music, which will close any music
//that is open because it is detecting the mouseover event.

StopMusic();
//If Video is loaded, then close it calling the clear vid function
ClearVid();
//If video controls are loaded, close them, this will close any
//video controles that are open because it is detecting the mouseover event.
CloseVideoControls();
//If there is a title Text on the screen, clear it.
ClearTitleText();


}; //end mouseAction onRollOver function

// 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(10, 10, 0, this);
message_txt.text = "Click Helpful Info for more information on using this CD";
}else{
message_txt.text = "error: XML not successfully loaded";
}
};
// load first XML menu
menu_xml.load("menu3.xml");

mahoganyhorizons
07-26-2006, 04:25 PM
Please help me!

Kraken
07-26-2006, 04:50 PM
dude, I don't have time to go through all that code. Can you post a simple FLA?

To the point, I would go about it by creating a number variable on the main timeline that shows where you are in the submenus. Set up your next and previous buttons to increment or decrement that variable in relation to the total number of submenus. You can also, at that point, fire the submenu's onRelease function if so needed:

next_btn.onRelease = function() {
if (currentSub < totalSubs) {
currentSub ++;
var tmp = myMenu["mySub" + currentSub];
tmp.onRollOver();
tmp.onRelease();
}
}


That's if you've coded your submenu's onRelease and onRollOver functions so you can call them from there.

Does that help?

mahoganyhorizons
07-26-2006, 04:54 PM
I'm trying to attach it here.

Thanks for looking at my problem.

mahoganyhorizons
07-26-2006, 04:57 PM
THis is the file, thanks so much for looking at my problem.

mahoganyhorizons
07-26-2006, 04:58 PM
The whole thing is generated on the fly though via actionscript, the buttons, and everything....

There is only one keyframe on the entire timeline that contains the actionscript that creates the whole thing.

It's pretty cool, as you can see, and it will be a very useful thing with our without the buttons, but I really would like to have them on there.

mahoganyhorizons
07-26-2006, 06:16 PM
Hey Kraken...I've attached a .fla, do you think you can help me?

Kraken
07-26-2006, 08:00 PM
It's difficult because it re-creates the menus on each rollover of the main menu, so you'd have to go deep into the code and make each submenu aware of where it sits in the xml heirarchy and in relation to its siblings. It's not too tough, but I don't have time to unravel it right now.

Maybe tonight...but I don't know...

mahoganyhorizons
07-26-2006, 08:10 PM
Hey, thanks so much for even taking a look at it. I'm stumped.

I appreciate your help.

mahoganyhorizons
07-26-2006, 08:51 PM
Can anyone who looks at this let me know if adding a Listner object to some sort of counter could solve my problem?

mahoganyhorizons
07-27-2006, 01:43 PM
Were you able to figure something out kraken?

Kraken
07-27-2006, 02:35 PM
Yeah, just a sec...I'll have something within the half-hour...

mahoganyhorizons
07-27-2006, 02:46 PM
Bless you Kraken, thanks so much dude.

Kraken
07-27-2006, 03:16 PM
Man, that was a pain in the tush. I don't know why they set that thing up to do some of the things it does, but I finally got it working. Take a look inside the playSoundFile function for where I attach the next and previous buttons. I also added 3 variables on the main timeline, currentIndex, myParent and totalNodes that keep track of where you are, which item is playing and how many total nodes there are in that section. You may have to do something similar in the video portion, but I don't have any more time to devote to this.

good luck!

mahoganyhorizons
07-27-2006, 03:34 PM
Hey dude, thanks.

Actually I modified a good portion of the code.

It was originally just set up to present a menu, load html files, load new menus, and load txt files.

I changed it around because I wanted a reusable xml container that would load various multimedia components.


I appreciate your help more than words could ever say, and would kiss you if I wasn't already married :)

THANKS SOOOO MUCH DUDE. you rock.

Man, that was a pain in the tush. I don't know why they set that thing up to do some of the things it does, but I finally got it working. Take a look inside the playSoundFile function for where I attach the next and previous buttons. I also added 3 variables on the main timeline, currentIndex, myParent and totalNodes that keep track of where you are, which item is playing and how many total nodes there are in that section. You may have to do something similar in the video portion, but I don't have any more time to devote to this.

good luck!

Kraken
07-27-2006, 03:48 PM
whoops...sorry, didn't mean to bash your code. It was just a little difficult to figure out. :)

mahoganyhorizons
07-27-2006, 04:00 PM
IT WORKS GREAT.

I moved that into another function, and I am able to call it within all the classes that I added to this file. THanks again.

Kraken
07-27-2006, 04:34 PM
rock on!