|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
can some1 help get my dynamic menu working?
i'm a real programming noob and am struggling to get my dynamic menu to work. i think it might be a referencing problem since my variables disappear. the code can be found here. i'm trying alternatives at the moment but none with the desired effect in mind.
i'm real stupid. |
|
#2
|
|||
|
|||
|
uhm, i see a lot of Flash 4 code in there... perhaps it would be easier if you used MX code and just created them dynamically?
i would try using attachMovie or duplicateMovieClip to get the same effects... what exactly are you trying to do with the menu? |
|
#3
|
|||
|
|||
|
i'm trying to generate a dynamic menu. initially the movie parses the array and initially builds the menu using the "item0client, item1client etc" values. when one selection is clicked it should rebuild the list to include the submenu items (e.g. item0name="sub menu title"). i'm not to wrried about what happens to the submenu items when clicked on for now since i can pretty much figure out how to get that working. also, if u examine the MC object "list_item" nested in the _root timeline you'll see that the initial values are loaded into frame 1. a mouseover event should change the colour in frame 2. however, as u have probably witnessed the values disappear.
if u could e-mail me so maybe we could further discuss the problem and i can give u a clearer idea if you're still confused (i know i am).please, any help u could provide would be most appreciated. my e-mail addy is mail@banzaiuk.com thanks. |
|
#5
|
|||
|
|||
|
okay, i believe i see the problem on why they disappearing.
Your dynamic text fields are keyframed out so that they are re-keyframed on almost every frame of the movieclip you are duplicating. This will cause the text fields to lose their variable value since it is only set when it is duplicated. Meaning, when you rollOver the button, it tells the movieclip to go to a different frame where the text field is re instantiated. But the variable is not set again. This should take care of your text problem if you do that (the moveiclips are still there, just the text isn't) the sub menu is a different thing tho, i would call a function that just repositions all of your duplicated elements according to the height of all of them. -bret |
|
#6
|
|||
|
|||
|
thanks bret. i see what you're getting at
how would recall the variable on mouseover then? like i said i'm a real noob. |
|
#7
|
|||
|
|||
|
well i would just clear the keyframes, keeping on textfield across all keyframes and then use code to dymically set the colour of the text in each of the frames. or you could have your textfield variable reference the _parent.variable instead of the variable in the timeline itself. either way... using one text field would definitely by less expensive tho
-bret |
|
#8
|
|||
|
|||
|
thanks bret. i told u i'm a noob. anyway, your suggestion worked a treat (used setRGB to manipulate the text filed colour). latest version is now here.
now i just gotta figure out how to make my menu work properly. can u explain what you were going on about in a bit more detail? |
|
#9
|
|||
|
|||
|
all right, here's what i did (in english rather than code) when i had to make a menu that expands. i would call a function that repositions all of my elements according to the height of each element.
function positionMenu get total elements in menu loop over that total number set the _y of each object according the previous element's height and _y + a spacer if it's the first element, just set to 0 And that's it... so, each element that is created will have a certain height; Every time someone clicks one nav item, it repositions all of them. i could most likely do a code example if you asked. -bret |
|
#10
|
|||
|
|||
|
if u would please, bret. you'd be saving me hours of hardship. you've been a great help already
![]() |
|
#11
|
|||
|
|||
|
okay, here's a little example i did... i'm using attachMovie instead of duplicate movie, but i wanted to illustrate how you could use one function to reposition all of the elements in your navigation using one function. here's the code (Commented ).
Code:
positionNav = function(){
//loops through the total number of main navigation elemnts
for(i=0;i<mainNav;i++){
//creates a variable that tells the height and Y of each main navigation button, and sets the next one
var nextY = navigation_mc["button"+(i-1)+"_mc"]._y + navigation_mc["button"+(i-1)+"_mc"]._height;
navigation_mc["button"+i+"_mc"]._y = nextY;
}
}
makeSubNav = function(obj,c){
//when you press a main nav, this gets called
//it attaches the same button, but moves it and positions it so that it looks like a sub nav
for(i=0;i<c;i++){
obj.attachMovie("buttonID","sub"+i,depth++);
obj["sub"+i]._x = obj._x + 10;
obj["sub"+i]._y = 16*i + 16;
obj["sub"+i].label_txt.text = "sub element " + i;
}
//notice that after we create this subnav, we have to reposition according to the new height (that the sub nav added)
positionNav();
}
killSubNav = function(obj,c){
//remove the sub nav as easily as we created it
for(i=0;i<c;i++){
obj["sub"+i].removeMovieClip();
}
positionNav();
}
//total nav items
mainNav = 10;
//create a navigation movieclip, so that it's all in one place to handle
this.createEmptyMovieClip("navigation_mc",depth++);
for(i=0;i<mainNav;i++){
//attach
navigation_mc.attachMovie("buttonID","button"+i+"_mc",depth++);
//set this open variable. This is used when i create and uncreate the sub nav.
//it starts as positive, so it tells me that a subnav doesn't exist
navigation_mc["button"+i+"_mc"].open = 1;
// this i value is used to dymically lable my buttons text fields
navigation_mc["button"+i+"_mc"].i = i;
//position it
navigation_mc["button"+i+"_mc"]._y = 16*i;
//set the nav text
navigation_mc["button"+i+"_mc"].label_txt.text = "Nav element " + i;
//tell the button to create a sub nav if it's not open, and to delete it if it's open
navigation_mc["button"+i+"_mc"].nav_btn.onRelease = function(){
this._parent.open *= -1;
if(this._parent.open < 0){
makeSubNav(this._parent,this._parent.i);
} else {
killSubNav(this._parent,this._parent.i);
}
}
}
//position the nav so it all looks right
positionNav();
so, i use a lot of stuff you won't need to, but my positionNav function is what is important. hopefully you get the general idea of it? the nice thing about how i have it set up is that we don't need to go burying for code, it's all on the main timeline. i just needed to give my button a linkage ID ("buttonID") and i'm set...write back with questions. -bret |
|
#12
|
|||
|
|||
|
and i suppose i should actually attach the file :P
|
|
#13
|
|||
|
|||
|
thanks bret. i kinda understand what u mean but this still dosen't help me fix the script. i'm not too hot on Flash programming and the method u provided dosen't achieve the visual effect i'm looking for (the text field is created one item at a time and loops until all the menu items have been generated). i've attatched some modifications and extended the array to include more submenu items. as u can see the item_count is incorrect (should be 15 not 19). things kinda go screwy from there on in. could u look at it and tell me where the problem lies? u can download the modified version here. i'd be prepared to give u a detailed explanation if you'd like so please don't hesitate to e-mail me if u can.
i'm never gonna get my website finished at this rate ![]() |
|
#14
|
|||
|
|||
|
hey, drop me an email, i've been really busy at work and school for the past, but i'll try and help if you can hold up for a few days
|
|
#15
|
|||
|
|||
|
sure bret. i can appreciate you're busy & am sincerely grateful for your time. what's your email address?
|
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > can some1 help get my dynamic menu working? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|