Hi flash coders,
I have created a menu dynamically and then when clicking on any of the
menu elements, I create a dynamic dropDown menu. All is well and working
but I am having problems deleting the dropDown menu and all it elements
when rolling over or clicking on a different menu element . After many
trials I have managed some code but it only removes the last element of
the dropDown menu (and its relative button).
My questions are:
1) what is the best way to create functions to control the dropDown
menus (there will be a few created when rolling over the elements of the
main menu)
2) What event can I use to remove the dropDown when the mouse rolls out
or clicks on a different main menu item.
3) How do I make sure that the 'for loop' will actually remove all of
the elements of the dropMenus and not just the last one (or first one
for that matter)
Some help would be much appreciated.
Following is the code I am using (I know that I should write fucntions
to make the code clearer and more modular but I would need to spend time
in doing it correctly and, given also my inexperience, I rather leave
it till last when I can revisit the code, if i'll have any spare time
:) :)) :
stop();
//
//____________ Init properties and variables _____________________________
var myTxt:Array = new Array("branding", "news", "about us", "print",
"marks", "contact");
var dropMenuArray = new Array("Sea Bounty", "Fire Brigade",
"CommonWealth Bank");
var subMenuArray:Array = new Array();
var dropBtnArray:Array = new Array();
var dropTextArray:Array = new Array();
var myX = 680;
var ySpacing:Number = 290;
var spaceMe:Number = 20;
var myName:String = "";
var btn:Button;
var subBtn:Button;
var subMenuEnable:Boolean = false;
var isDone:Boolean = false;
//
//____________________create the textFields for the
subMenuItems___________________
//
for (i=0; i<myTxt.length; i++) {
_root.createTextField("mytext"+i, this.getNextHighestDepth(), myX,
0, 100, 30);
myId = _root["mytext"+[i]];
myId._y = ySpacing;
ySpacing += 20;
//
//trace(myTxt[i]);
myId.text = myTxt[i];
//
//
//____________Format the text of the subMenuItems_____________________
//
myId.border = false;
myformat = new TextFormat();
myformat.font = "Verdana";
myformat.size = 14;
myformat.bold = false;
myformat.color = 0x555555;
myformat.align = "right";
//
myId.selectable = false;
myId.setTextFormat(myformat);
//
//__create an Array with the submenuItems to be used in the buttons
control function______
//
subMenuArray.push(myId.text);
//trace(subMenuArray[i]);
//
//____________attach a button (on top of) to each textFields__________
//
btn = this.attachMovie("butt_btn", myTxt[i],
this.getNextHighestDepth());
btn._alpha = 0;
btn._x = myX;
btn._y = myId._y;
//
//***********ATTACH BEHAVIOUR TO THE BUTTONS***********
//
//__________________RollOver_________________________________
//
btn.onRollOver = function() {
myName = this._name;
//trace("this will load the "+myName +" subMenu")
for (e=0; e<subMenuArray.length; e++) {
if (myName == subMenuArray[e]) {
//trace(subMenuArray[e]);
reformat = new TextFormat();
reformat.color = 0x658DAD;
lable = _root["mytext"+[e]];
//trace(lable);
lable.setTextFormat(reformat);
//trace("The lable colour is "+reformat.color);
}
}
};
//
//____________________RollOut__________________________
//
btn.onRollOut = function() {
myName = this._name;
for (e=0; e<subMenuArray.length; e++) {
if (myName == subMenuArray[e]) {
reformat = new TextFormat();
reformat.color = 0x555555;
lable = _root["mytext"+[e]];
lable.setTextFormat(reformat);
}
}
};
//
//____________________On Press______________________
//
btn.onPress = function() {
myName = this._name;
for (e=0; e<subMenuArray.length; e++) {
if (myName == subMenuArray[e]) {
reformat = new TextFormat();
reformat.color = 0x555555;
lable = _root["mytext"+[e]];
lable.setTextFormat(reformat);
subMenuEnable = true;
//isDone = false;
dropMenu(this);
}
}
};
//
//_______________On Release___________________________
//
btn.onRelease = function() {
myName = this._name;
//trace(this._name);
_root.createEmptyMovieClip("dis_mc", _root.getNextHighestDepth());
dis_mc._x = 100;
dis_mc._y = 70;
//trace("images/contents/"+myName+".jpg")
dis_mc.loadMovie(myName+".jpg", this.dis_mc);
};
//
//_________create an array to use later to control the
buttons_____________
//
//myBtnArray.push(btn);
//trace("The y for "+myBtnArray[i]+" is: "+btn._y+" and its x is:
"+btn._x);
//
}
//
//*****CREATE THE TEXTFIELDS AND THE INVISIBLE BUTTONS FOR THE SUB MENU*****
//
function dropMenu(thisOne) {
if (!isDone && subMenuEnable == true) {
for (i=0; i<dropMenuArray.length; i++) {
_root.createTextField("mySubText"+i,
this.getNextHighestDepth(), thisOne._x-100, 0, 130, 25);
newId = _root["mySubText"+[i]];
newId._y = thisOne._y+spaceMe;
spaceMe += 25;
//
newId.text = dropMenuArray[i];
//
//
//____________Format the text of the
dropMenuItems_____________________
//
format = new TextFormat();
//format.border = true;
//format.backgroundColor = 0xE6CCE6;
format.font = "Verdana";
format.size = 12;
format.bold = false;
format.color = 0xF0A65B;
format.align = "right";
format.autoSize = "center";
//
newId.selectable = false;
newId.setTextFormat(format);
dropTextArray.push(newId);
//trace(dropTextArray)
//
//____________attach a button (on top of) to each
textFields__________
//
subBtn = this.attachMovie("butt_btn", dropMenuArray[i],
this.getNextHighestDepth());
subBtn._xscale = newId._width;
//subBtn._yscale = newId._height;
//subBtn.blendMode = "darken";
subBtn._alpha = 30;
subBtn._x = newId._x;
subBtn._y = newId._y;
dropBtnArray.push(subBtn);
//trace(dropBtnArray);
trace(isDone) //this traces 'false' for the first iteration
but becomnes true afterwards
//
//
//___________control this subMenu buttons_______________
//
subBtn.onRollOver = function() {
myName = this._name;
for (e=0; e<subMenuArray.length; e++) {
if (myName == subMenuArray[e]) {
reformat = new TextFormat();
reformat.color = 0x555555;
lable = _root["mytext"+[e]];
lable.setTextFormat(reformat);
}
};
isDone = true;
}
} else if (isDone) {
//trace(dropBtnArray.length)
for (z=0; z<dropBtnArray.length; z++) {
//trace(newId);
//trace(subBtn);
removeMovieClip(this.subBtn);
newId.removeTextField(dropTextArray[z]);
this.dropTextArray.shift();
this.dropBtnArray.shift();
//trace(dropTextArray)
}
subMenuEnable = false;
}
idDone = false;
}
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com