ice78991
Programmer
- Nov 20, 2006
- 216
I am trying to create a set of html type links in flash. I am using an array to contain the link text and I have created a seperate movie clip for each link ( with a textfield embedded)
My problem is that I am trying to get the movie clip to fit perfectly around its textfield so the onRollOver is right on the link and the links are spaced correctly.
When I use the following code the result is as follows
link1xxlink2xxxxxlink3
xxxxxxxxxxxxxxxxxxxxxx
x marks where the onRollOvers can be activated
The main problem is that links 2 and 3 are further apart than links 1 and 2. Also, onRollOvers are activated a few pixels off the links
Here's the code
//get the width of each link
var widths:Array = new Array();
var heights:Array = new Array();
for(var i:Number=0;i<links.length;i++)
{
var extentObj:Object=linksTextFormat.getTextExtent(links);
widths = extentObj.textFieldWidth;
heights = extentObj.textFieldHeight;
}
var prevWidth = 0;
var prevX = LINKXOFFSET;
for(var i:Number = 0; i< links.length; i++)
{
var mc:MovieClip = createEmptyMovieClip("link"+i+"_mc",i+1);
mc.createTextField("link_txt",1,0,0,widths+8,heights+8); //8 accounts for the text field border ??????
var txt:TextField = mc.link_txt;
mc._x = prevX+prevWidth+LINKSMARGIN;
mc._y = 0;
prevX = mc._x;
prevWidth = widths;
txt.setNewTextFormat(linksTextFormat);
txt.text = links;
}
My problem is that I am trying to get the movie clip to fit perfectly around its textfield so the onRollOver is right on the link and the links are spaced correctly.
When I use the following code the result is as follows
link1xxlink2xxxxxlink3
xxxxxxxxxxxxxxxxxxxxxx
x marks where the onRollOvers can be activated
The main problem is that links 2 and 3 are further apart than links 1 and 2. Also, onRollOvers are activated a few pixels off the links
Here's the code
//get the width of each link
var widths:Array = new Array();
var heights:Array = new Array();
for(var i:Number=0;i<links.length;i++)
{
var extentObj:Object=linksTextFormat.getTextExtent(links);
widths = extentObj.textFieldWidth;
heights = extentObj.textFieldHeight;
}
var prevWidth = 0;
var prevX = LINKXOFFSET;
for(var i:Number = 0; i< links.length; i++)
{
var mc:MovieClip = createEmptyMovieClip("link"+i+"_mc",i+1);
mc.createTextField("link_txt",1,0,0,widths+8,heights+8); //8 accounts for the text field border ??????
var txt:TextField = mc.link_txt;
mc._x = prevX+prevWidth+LINKSMARGIN;
mc._y = 0;
prevX = mc._x;
prevWidth = widths;
txt.setNewTextFormat(linksTextFormat);
txt.text = links;
}