I am using code from a tutorial the was originaly designed to create navigation buttons in the root time line. I have placed the code inside a movie clip and change all the “_root” tags to “this” tags. When I test the animation it works however on pressing the buttons it does not trigger the function to load in the external movies.
I have attached the fla and my AS is below. This AS is inside the mc_content movie clip on frame 24.
// NAVIGATION ARRAYS
// This first array contains the names of the top menu (menu1) options.
var menuTitle1 = new Array("Homepage","Events","Forum","Gallery", "Biography", "Press", "Contact");
// This second array contains the names of content movies for the top menu choices.
var menuSWF1 = new Array("home.swf","events.swf","forum.swf","gallery.swf","biography.swf","press.swf","contact.swf");
// If an option doesn't load any content, but simply opens another sub-menu, then use the string 'none' in place of
// the content name. In this example only the fist option in each menu will open content.
// CONTROL VARIABLES
/*
These will define key aspects of our navigation layout. They are presented grouped together
after the Navigation variables to make editing the interface easier.
*/
// Navigation co-ordinates
// These define the top-left position of our navigation
var navX=171;
var navY=-187.7;
// Menu Size
// These determine the number of menus and number of options per menu
var menus=1;
var options=7;
// Spacing variable
// 'spacingX' is the distance between left-hand edges of the menus
// 'spacingY' is the distance between top edges of the menu options
var spacingX=160;
var spacingY=22;
// 'newContent' tells the shutter movie the file to load in
// Set this to the home page content as this will be loaded in initially
var newContent="home.swf";
// OTHER VARIABLES
// Initiate soem variables here which will be used to control the state of the navigation by later functions
// We'll keep track of whether the shutter is open or not to help keep the animation synchronised
var shutterOpen=true;
// We are going to use setInterval to control the diplay of the otions.
// 'openNext' will keep track of which is next to display
var openNext=1;
// FUNCTIONS
// Define our functions to control the shutter and the opening of menus
/*
closeShutter will be called when new content is to be loaded
The 'arrayVal' parameter is the suffix of the navigation array needed
The 'option' parameter refers to the option selected
Reference the correct navigation content array by constructing the array name:
If arrayVal is '1_3' then this["menuSWF"+arrayVal] evaluates to 'this.menuSWF1_3'
The required content is then found from this array.
The options are numbered 1 to 5 but the contents of arrays are numbered from 0,
so 'this.menuSWF1_3[0]' actually refers to the content for option 1
*/
function closeShutter(arrayVal,option){
// Only operate the shutter if the content value isn't 'none'
if(this["menuSWF"+arrayVal][option-1]!="none"){
// set the variable 'newContent' to the required file
newContent=this["menuSWF"+arrayVal][option-1];
// If the shutter is open send its playhead to 'open' and play
if(shutterOpen){
shutter.gotoAndPlay('open');
// If the shutter is already loading in content send it to 'shut' so that
// the shutter doesn't open and close again, but just starts loading different content
}else{
shutter.gotoAndPlay('shut');
}
}
}
/*
This function will display the contents of the chosen menu, incorporating the staggered appearance effect for the
individual options. It requires the menu (eg, 'this.menu2') and the suffix for the array to be used (eg, '1_3_2')
*/
openMenu=function(menu, arrayVal){
// Before making menu visible, first make sure all the options within it are reset to the start and invisible
for(var i=1;i<=options;i++){
menu["option"+i].gotoAndStop('start');
menu["option"+i]._visible=false;
}
// Make menu visible
menu._visible=true;
// The number of options to show is determined by the number of elements in the appropriate 'menuTitles' array.
this.numberOptions=this["menuTitle"+arrayVal].length;
// Loop through these options and assign the correct string to the 'title' text field
for(var i=0;i<numberOptions;i++){
opt=i+1;
menu["option"+opt].title=this["menuTitle"+arrayVal]*;
}
// Make sure that setInterval has been cleared. This ensures that we don't confuse our counter
// if we try to open a menu whilst another is still opening
clearInterval(this.openInterval);
// Set the next option to be opened to 1
this.openNext=1;
// Call setInterval. This will call 'openOption' on root every 0.07 seconds until clearInterval is called
// Passing 'menu' ensures 'openOption' opens the options of the correct menu
openInterval = setInterval(this,"openOption",70,menu);
}
// 'openOption' displays an individual option as defined by 'openNext'
function openOption(menu){
// if this menu option has been defined in the navigtion variables,
// make it visible and send playhead to 'start'
if(openNext<=this.numberOptions){
menu["option"+this.openNext]._visible=true;
menu["option"+this.openNext].gotoAndPlay('start');
this.openNext++;
// otherwise all options are already displayed so clear interval
}else{
this.openNext=1;
clearInterval(openInterval);
}
}
// ATTACH AND CREATE MOVIECLIPS
// Attach shutter movie and set its co-ordinates
attachMovie("shutter","shutter",1000);
shutter._x=-341.1;
shutter._y=-162;
// Create 'content' movie. This is an empty movie clip on a lower level
// than the shutter. We will load other SWFs into 'content'
createEmptyMovieClip("content",500);
content._x=-339.1;
content._y=-160;
// GENERATE THE MENUS
/*
Create new movies called menu1, menu2, menu3 etc depending on the number specified by 'menus'
Assign functions to these menus to allow the options contained within to be closed and opened
Attach instances of 'menuOptions' to the menus called option1, option2, etc as specified by options
Assign functions to the options to allow sub-menus to be opened on click
*/
for(var i=1; i<=menus; i++){
// CREATE AND POSITION MENU
// menu created and placed on a level not yet occupied
createEmptyMovieClip("menu"+i,2000+i);
// menu moved to correct position according to which tier it is in
this["menu"+i]._x=navX+(i-1)*spacingX;
this["menu"+i]._y=navY;
// set a variable to define which menu this is
this["menu"+i].menuID=i;
// set a variable to say which option has been opened, this will initially be 1
this["menu"+i].arrayVal="1";
// ADD FUNCTIONS TO MENU
// Define a function 'resetMenu' for this menu which resets all the options from the selected state.
// We can stop a particular option from being reset by passing its number as the variable 'spare'
// If we want all options to be reset, pass 0 as 'spare'
this["menu"+i].resetMenu=function(spare){
var opt=1;
// Loop through all options for this menu
while(this["option"+opt]){
// Only reset if not the option we have designated spare
if(opt!=spare){
// reset the option
this["option"+opt].open=false;
this["option"+opt].gotoAndStop("over");
}
opt++;
}
// if this is not last tier reset and make invisible any subsequent tiers as well
if(this["menu"+(this.menuID+1)]){
this["menu"+(this.menuID+1)]._visible=false;
this["menu"+(this.menuID+1)].chosenOption=0;
// by calling this same function on the next tier it will reset and make invisible the next tier
// after that and so on, until all menus further down the navigation are closed
this["menu"+(this.menuID+1)].resetMenu(0);
}
}
// make this menu invisible until specifically opened with 'openMenu'
this["menu"+i]._visible=false;
// ADD OPTIONS TO MENU
for(var j=1;j<=options;j++){
// ATTACH AND POSITION OPTION
// attach an instance of "menuOption" from the library
this["menu"+i].attachMovie("menuOption", "option"+j, j);
// set its co-ordinates within its parent menu
this["menu"+i]["option"+j]._x=0;
this["menu"+i]["option"+j]._y=(j-1)*this.spacingY;
// the variable 'open' will be used to control the option timeline
this["menu"+i]["option"+j].open=false;
// set a variable to define which menu this is
this["menu"+i]["option"+j].optionID=j;
// ASSIGN FUNCTIONS TO OPTION
// create button roll-over function for the option
this["menu"+i]["option"+j].onRollOver=function(){
// on roll-over send the playhead to 'over' unless the variable 'open' is already true
if(!this.open)this.gotoAndPlay("over");
}
// create button roll-out function for the option
this["menu"+i]["option"+j].onRollOut=function(){
// on roll-over send the playhead to stop at 'over' unless the variable 'open' is already true
if(!this.open)this.gotoAndStop("over");
}
// create button on-press function for the option
this["menu"+i]["option"+j].onPress=function(){
// on press send the playhead to 'open'
// Having defined the correct content to be loaded the funtion 'closeShutter' is called
// which will load the new content in
this.gotoAndPlay("open");
this.closeShutter(this._parent.arrayVal,this.optionID);
}
// define a function that opens the sub-menu for this option
this["menu"+i]["option"+j].openSub=function(){
this.open=true;
nextMenu=this["menu"+(this._parent.menuID+1)];
this._parent.resetMenu(this.optionID);
nextMenu.arrayVal=this._parent.arrayVal+"_"+this.optionID;
this.openMenu(nextMenu,nextMenu.arrayVal);
}
}
}
Thanks.