-
Scope and Array Access Problem
Hello,
I'm trying to initiate two corresponding buttons at the same time but I'm getting lost. I basically want the instances of menuBtns and menuTxtBtns array to play at the same time you rollOver/rollOut either button. So when you rollover the txt block the circle info pops up and visa versa. Please see link to clarify.
Thank You, Jacob
SWF Example
http://alt.coxnewsweb.com/statesman/...rader_map.html
Actionscript Code:
stop();
//btnCircle Array var menuBtns:Array=[btnNum14,btnNum15,btnNum16,btnNum17,btnNum18];
//Txt Block Array var menuTxtBtns:Array=[txtBlock14,txtBlock15,txtBlock16,txtBlock17,txtBlock18];
//btnCircle/Txt Block Link Array var menuLinks:Array = new Array(); menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum14 - txtBlock14 menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum15 - txtBlock15 menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum16 - txtBlock16 menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum17 - txtBlock17 menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum18 - txtBlock18
//Loop to addListeners function addListeners():void { //For Loop to addListeners to btnCircles for (var i:uint = 0; i < menuBtns.length; i++) { menuBtns[i].addEventListener(MouseEvent.ROLL_OVER,rollOverMenu); menuBtns[i].addEventListener(MouseEvent.ROLL_OUT,rollOutMenu); menuBtns[i].addEventListener(MouseEvent.CLICK,clickMenu); menuBtns[i].num=i; //Makes the Hand appear menuBtns[i].buttonMode=true; //addListeners to menuTxtBtns menuTxtBtns[i].addEventListener(MouseEvent.ROLL_OVER,rollOverMenuTxt); menuTxtBtns[i].addEventListener(MouseEvent.ROLL_OUT,rollOutMenuTxt); menuTxtBtns[i].addEventListener(MouseEvent.CLICK,clickMenuTxt); menuTxtBtns[i].num=i; //Makes the Hand appear menuTxtBtns[i].buttonMode=true; } }
//<-------------------------------- Buttons for Cirlce Buttons -----------------------------------> function clickMenu(event:MouseEvent):void { var btnCircle:MovieClip=MovieClip(event.currentTarget); //Var holding current link in the menuLinks array var url:String=menuLinks[btnCircle.num]; //trace(btnCircle.name+" : "+url); var request:URLRequest=new URLRequest(url); navigateToURL(request, "_blank"); //Makes currently selected btnCircle on top depth this.setChildIndex(btnCircle,this.numChildren-1); }
//RollOver Mouse Function function rollOverMenu(event:MouseEvent):void { //Targeting the current btn selected var btnCircle:MovieClip=MovieClip(event.target); btnCircle.gotoAndPlay("btnRollOver"); //Currently selected btnCircle on top depth btnCircle.parent.setChildIndex(btnCircle,btnCircle.parent.numChildren-1); }
//RollOut Mouse Function function rollOutMenu(event:MouseEvent):void { var btnCircle:MovieClip=MovieClip(event.target); btnCircle.gotoAndPlay("btnRollOut"); //Makes currently selected btnCircle on top depth this.setChildIndex(btnCircle,this.numChildren-1); }
//<------------------ Buttons for Dealership Information Text Blocks -----------------------> //CLICK Mouse Function function clickMenuTxt(event:MouseEvent):void { var btnTxtBlock:MovieClip=MovieClip(event.currentTarget); //Var holding current link in the menuLinks array var url:String=menuLinks[btnTxtBlock.num]; //trace(btnCircle.name+" : "+url); var request:URLRequest=new URLRequest(url); navigateToURL(request, "_blank"); }
//RollOver Mouse Function function rollOverMenuTxt(event:MouseEvent):void { //Targeting the current btn selected var btnTxtBlock:MovieClip=MovieClip(event.currentTarget); btnTxtBlock.gotoAndPlay("btnRollOver");
}
//RollOut Mouse Function function rollOutMenuTxt(event:MouseEvent):void { var btnTxtBlock:MovieClip=MovieClip(event.currentTarget); btnTxtBlock.gotoAndPlay("btnRollOut"); }
//Runs addListener function addListeners();
-
You need to associate the two corresponding buttons with each other, so that you can activate them together.
First, separate the content of the event handlers into functions that you can pass buttons into, then call those new functions from the handlers. This will let you activate a button without having to react to an event.
Second, set a property on each circle that points to the corresponding text button and vice versa. Now when activating one, also activate the other.
Code:
stop();
//btnCircle Array
var menuBtns:Array=[btnNum14,btnNum15,btnNum16,btnNum17,btnNum18];
//Txt Block Array
var menuTxtBtns:Array=[txtBlock14,txtBlock15,txtBlock16,txtBlock17,txtBlock18];
//btnCircle/Txt Block Link Array
var menuLinks:Array = new Array();
menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum14 - txtBlock14
menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum15 - txtBlock15
menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum16 - txtBlock16
menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum17 - txtBlock17
menuLinks.push("http://acuraaustin.mcdavid.com/");//btnNum18 - txtBlock18
//Loop to addListeners
function addListeners():void {
//For Loop to addListeners to btnCircles
for (var i:uint = 0; i < menuBtns.length; i++) {
menuBtns[i].addEventListener(MouseEvent.ROLL_OVER,rollOverMenu);
menuBtns[i].addEventListener(MouseEvent.ROLL_OUT,rollOutMenu);
menuBtns[i].addEventListener(MouseEvent.CLICK,clickMenu);
menuBtns[i].num=i;
menuBtns[i].txtButton = menuTxtBtns[i];
//Makes the Hand appear
menuBtns[i].buttonMode=true;
//addListeners to menuTxtBtns
menuTxtBtns[i].addEventListener(MouseEvent.ROLL_OVER,rollOverMenuTxt);
menuTxtBtns[i].addEventListener(MouseEvent.ROLL_OUT,rollOutMenuTxt);
menuTxtBtns[i].addEventListener(MouseEvent.CLICK,clickMenuTxt);
menuTxtBtns[i].num=i;
menuTxtBtns[i].circleButton = menuBtns[i];
//Makes the Hand appear
menuTxtBtns[i].buttonMode=true;
}
}
//<-------------------------------- Buttons for Cirlce Buttons ----------------------------------->
function clickMenu(event:MouseEvent):void {
var btnCircle:MovieClip=MovieClip(event.currentTarget);
//Var holding current link in the menuLinks array
var url:String=menuLinks[btnCircle.num];
//trace(btnCircle.name+" : "+url);
var request:URLRequest=new URLRequest(url);
navigateToURL(request, "_blank");
//Makes currently selected btnCircle on top depth
bringToTop(btnCircle)
}
//RollOver Mouse Function
function rollOverMenu(event:MouseEvent):void {
//Targeting the current btn selected
var btnCircle:MovieClip=MovieClip(event.target);
activateCircle(btnCircle);
activateTxtBlock(btnCircle.txtButton);
}
function activateCircle(btnCircle:MovieClip):void{
btnCircle.gotoAndPlay("btnRollOver");
bringToTop(btnCircle);
}
//RollOut Mouse Function
function rollOutMenu(event:MouseEvent):void {
var btnCircle:MovieClip=MovieClip(event.target);
deactivateCircle(btnCircle);
deactivateTxtBlock(btnCircle.txtButton);
}
funtion deactivateCircle(btnCircle:MovieClip):void{
btnCircle.gotoAndPlay("btnRollOut");
bringToTop(btnCircle);
}
//<------------------ Buttons for Dealership Information Text Blocks ----------------------->
//CLICK Mouse Function
function clickMenuTxt(event:MouseEvent):void {
var btnTxtBlock:MovieClip=MovieClip(event.currentTarget);
//Var holding current link in the menuLinks array
var url:String=menuLinks[btnTxtBlock.num];
//trace(btnCircle.name+" : "+url);
var request:URLRequest=new URLRequest(url);
navigateToURL(request, "_blank");
}
//RollOver Mouse Function
function rollOverMenuTxt(event:MouseEvent):void {
//Targeting the current btn selected
var btnTxtBlock:MovieClip=MovieClip(event.currentTarget);
activateTxtBlock(btnTxtBlock);
activateCircle(btnTxtBlock.circleButton);
}
function activateTxtBlock(btnTxtBlock:MovieClip):void{
btnTxtBlock.gotoAndPlay("btnRollOver");
}
//RollOut Mouse Function
function rollOutMenuTxt(event:MouseEvent):void {
var btnTxtBlock:MovieClip=MovieClip(event.currentTarget);
deactivateTxtBlock(btnTxtBlock);
deactivateCircle(btnTxtBlock.circleButton);
}
function deactivateTxtBlock(btnTxtBlock:MovieClip):void{
btnTxtBlock.gotoAndPlay("btnRollOut");
}
function bringToTop(clip:DisplayObject):void{
clip.parent.addChild(clip);
}
//Runs addListener function
addListeners();
I probably missed or typoed something.
-
Or...
Code:
function rollOverMenu(event:MouseEvent):void {
var btnCircle:MovieClip=MovieClip(event.target);
btnCircle.gotoAndPlay("btnRollOver");
menuTxtBtns[btnCircle.num].gotoAndPlay("btnRollOver");
}
function rollOutMenu(event:MouseEvent):void {
var btnCircle:MovieClip=MovieClip(event.target);
btnCircle.gotoAndPlay("btnRollOut");
menuTxtBtns[btnCircle.num].gotoAndPlay("btnRollOut");
}
//
function rollOverMenuTxt(event:MouseEvent):void {
var btnTxtBlock:MovieClip=MovieClip(event.currentTarget);
btnTxtBlock.gotoAndPlay("btnRollOver");
menuBtns[btnTxtBlock.num].gotoAndPlay("btnRollOver");
}
function rollOutMenuTxt(event:MouseEvent):void {
var btnTxtBlock:MovieClip=MovieClip(event.currentTarget);
btnTxtBlock.gotoAndPlay("btnRollOut");
menuBtns[btnTxtBlock.num].gotoAndPlay("btnRollOut");
}
-
Thank You, worked great!!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|