Hi all
I followed a tutorial online to create a flash menu that ‘knew’ which page it was on via javascript (http://www.flashmagazine.com/tutoria…ng_javascript/).
The menu worked until I assigned links to the buttons.
The code for the menu is:
stop();
// setup our 5 buttons
item1.addEventListener(MouseEvent.CLICK, gotoURL);
item2.addEventListener(MouseEvent.CLICK, gotoURL);
item3.addEventListener(MouseEvent.CLICK, gotoURL);
item4.addEventListener(MouseEvent.CLICK, gotoURL);
item5.addEventListener(MouseEvent.CLICK, gotoURL);
// grab variables
try {
var key:String;
var val:String;
var flashvars:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (key in flashvars) {
val = String(flashvars[key]);
if(key == "item"){ // If the parameter is called 'item'...
if(val.substr(0,4) == "item"){ // ... and the name of the button starts with the characters 'item'...
// ... we can extract the number-part of the item-name and go to the correct frame
var frameToGoTo:Number = Number( val.substr(4,1) );
gotoAndStop( frameToGoTo+1 );
}
}
}
} catch (error:Error) {
// what to do if an error occurs
}
// Get the new page
function gotoURL(e:MouseEvent):void {
// First we grab the URL of the HTML document and split it into an array
var htmlUrl:String = ExternalInterface.call("window.location.href.toString");
// split the string at the questionmark
var splitUrl:Array = htmlUrl.split("?");
// use only the first part (ditch existing parameters)
var trimmedUrl:String = splitUrl[0];
// get the name of the button clicked and set it as a parameter
var parameters:String = "item="+e.currentTarget.name;
trace("parameters "+parameters);
// combine url and parameters with a new questionmark
var requester:URLRequest = new URLRequest(trimmedUrl+"?"+parameters);
// reload the page
navigateToURL(requester, '_self');
}
And the code for the buttons is:
item1.addEventListener(MouseEvent.CLICK,goindex1);
function goindex1(e:MouseEvent){
var request = new URLRequest("http://www.designsubway.com/index1.html?item=item1");
navigateToURL(request,"_self");
}
item2.addEventListener(MouseEvent.CLICK,goindex2);
function goindex2(e:MouseEvent){
var request = new URLRequest("http://www.designsubway.com/index2.html?item=item2");
navigateToURL(request,"_self");
}
item3.addEventListener(MouseEvent.CLICK,goindex3);
function goindex3(e:MouseEvent){
var request = new URLRequest("http://www.designsubway.com/index3.html?item=item3");
navigateToURL(request,"_self");
}
item4.addEventListener(MouseEvent.CLICK,goindex4);
function goindex4(e:MouseEvent){
var request = new URLRequest("http://www.designsubway.com/index4.html?item=item4");
navigateToURL(request,"_self");
}
item5.addEventListener(MouseEvent.CLICK,goindex5);
function goindex5(e:MouseEvent){
var request = new URLRequest("http://www.designsubway.com/index5.html?item=item5");
navigateToURL(request,"_self");
}
As you can see item1 should go to http://www.designsubway.com/index1.html?item=item1. The ?item=item1 part means that the button ‘item1’ is highlighted.
This works for fine if you click the buttons incrementally (button1 then button2…) but doesn’t worki if you go back down through the sequence, only the part after the ‘?’ changes not that page itself.
I am sorry if this is not explained very well but I am a total noob. You can see a working example at http://www.designsubway.com/index1.html?item=item1
Any help would really be appreciated, thank you.