|
-
dynamic text alignment - need help with code
Hi guys,
I've been following an xml tutorial webdesign tutorial, as I'm pretty new to the whole coding side of things, I've copied their code into my own design, which has been going fine up until this point.
In the tutorials the dynamic menus were alligned vertically, in my site I want them to run horizontally, well I managed to suss out how to realign them, the problem is that the spacing between each button is set according to the end of each (invisible) button.
This makes each gap a different size and makes the layout look really clunky.
I'm wondering if theres a line of code I can insert, which defines the size of each button according to the size of the text, or alternately, that starts the spacing from the end of the text rather than the button.
dont know if it helps, but here is the code I am currently using
function SS_createButtons() {
_root.btn_projects_main._visible = 0;
btn_xPos = _root.btn_projects_main._x;
btn_yPos = _root.btn_projects_main._y;
btn_xDistance = 100;
btn_yDistance = 50;
btn_numOfRows = 1;
btn_yMax = btn_yPos + ((btn_numOfRows - 1) * btn_yDistance);
for (count = 0; count < _root.projectCount; count++) {
duplicateMovieClip(_root.btn_projects_main, "btn_projects" + count, count);
_root["btn_projects" + count]._x = btn_xPos;
_root["btn_projects" + count]._y = btn_yPos;
_root["btn_projects" + count].text = namesArray[count];
if(btn_yPos == btn_yMax){
btn_xPos = btn_xPos + btn_xDistance;
btn_yPos = _root.btn_projects_main._y;
} else {
btn_yPos = btn_yPos + btn_yDistance;
}
}
SS_load_project(0);
tellTarget(_root.btn_projects0){
gotoAndPlay(3);
}
_root.curButton = "0";
}
any help/ideas would be massively appreciated
-
You can get the text's width with textfield.textWidth.
Hopefully, inside the mcs, your textfield has an instance name (i don't see where/how you add text in that code sample). If not, you can do so from the properties panel.
gparis
-
Hmm ok that definatly seems like the right area to be looking at, but due to my severe lack of coding experience, I'm having major problems getting it to work!
In answer to your question, the textfield itself doesn't have an instance name, it is part of an instance of a hidden button, which is duplicated for each new project outlined in the xml.
duplicateMovieClip(_root.btn_projects_main, "btn_projects" + count, count);
_root["btn_projects" + count]._x = btn_xPos;
_root["btn_projects" + count]._y = btn_yPos;
_root["btn_projects" + count].text = namesArray[count];
At present each new button is set to the size of the main hidden button, and the x distance is added to that size (btn_xDistance = 100
I'm wondering if theres a way to set that size + the textWidth (eg btn_xDistance = 100 + _root["btn_projects" + count].textWidth)
I have tried this, but it just makes all the buttons pile up on top of each other - any thoughts? Would it help to give the textfield an instance name?
Thanx for your help - D
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
|