[FMX] Can someone explain why one works but the other does not?

I am popultating a dynamic text box with values from a database. I need/want the location of the text box to be at a random position on the stage, so I have been using:
[AS]
//Put text in text box
Services_mc.Services_text_mc.Services_txt.text = Services_array[count];

//Move the text feild to a random position on the stage, but make
//sure that the entire text will fit
Services_mc._x = Math.random() * (Scene_Width - Services_mc.Services_text_mc.Services_txt.textWidth);
Services_mc._y = Math.random() * (Scene_Height - Services_mc.Services_text_mc.Services_txt.textHeight);
[/AS]
I would like to make the text a link to a section on my site, so I was trying to follow the thread “Dynamic text with HTML code” So I changed my code to :
[AS]
//Build html to go in text field from the two arrays that are built from the database
//where count is the index of the values that we are on
Services_str = “<a href=’”+Services_Links_array[count]+"’>"+Services_array[count]+"</a>";
Services_mc.Services_text_mc.Services_txt.html = true;
Services_mc.Services_text_mc.Services_txt.htmlText = Services_str;

//Move the text feild to a random position on the stage, but make
//sure that the entire text will fit
Services_mc._x = Math.random() * (Scene_Width - Services_mc.Services_text_mc.Services_txt.textWidth);
Services_mc._y = Math.random() * (Scene_Height - Services_mc.Services_text_mc.Services_txt.textHeight);
[/AS]
In doing a “List Variables” in Debug I see the following (I did a PHP code block so that it would not render my html in the text box):


Level #0:
Variable _level0.$version = "WIN 6,0,21,0"
Variable _level0.Services = "Service 1,Service 2,Service 3,Service 4,Service 5"
Variable _level0.services_links = "1,2,3,4,5"
Variable _level0.status = "1"
Variable _level0.Services_array = [object #1, class 'Array'] [
    0:"Service 1",
    1:"Service 2",
    2:"Service 3",
    3:"Service 4",
    4:"Service 5"
  ]
Variable _level0.Services_Links_array = [object #2, class 'Array'] [
    0:"1",
    1:"2",
    2:"3",
    3:"4",
    4:"5"
  ]
Variable _level0.Scene_Width = 483
Variable _level0.Scene_Height = 115
Variable _level0.count = 0
Variable _level0.Services_str = "<a href='1'>Service 1</a>"
Variable _level0.junk1 = 0
Variable _level0.junk2 = 2
Movie Clip: Target="_level0.Services_mc"
Movie Clip: Target="_level0.Services_mc.Services_text_mc"
Edit Text: Target="_level0.Services_mc.Services_text_mc.Services_txt"
    variable = "Services_text",
    text = "Service 1",
    htmlText = "<TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Arial\" SIZE=\"25\" COLOR=\"#B81215\"><A HREF=\"1\" TARGET=\"\">Service 1</A></FONT></P></TEXTFORMAT>",
    html = true, textWidth = 0, textHeight = 2, maxChars = null,
    borderColor = 0x000000, backgroundColor = 0xFFFFFF, textColor = 0xB81215, border = false,
    background = false, wordWrap = false, password = false, multiline = false,
    selectable = false, scroll = 1, hscroll = 0, maxscroll = 1,
    maxhscroll = 0, bottomScroll = 1,
    type = "dynamic",
    embedFonts = true, restrict = null, length = 9, tabIndex = undefined,
    autoSize = "none",
    condenseWhite = false

I see that the htmlText is getting set, and with what looks like good html, and I see that text gets set with the non html part from the htmlText. This brings my questions: Am I just going the htmlText part wrong? Is it not possiable to calculate the width of the text when html is set to “true”?

Thanks for reading my post and any pointers you may give.
Jimmy Puckett

Hi,

I can’t find anywhere in your post where you say what’s not working…

Is it not possible to calculate the width of the text when html is set to “true”?

try tracing the values…


trace(Services_mc.Services_text_mc.Services_txt.textWidth);

Thank you for replying. As for what is not working, the html does not show up in the dynamic text field and the textWidht and textHeight does not return the correct value.

The 32nd line of the “List Variables” dump shows:


html = true, textWidth = 0, textHeight = 2, maxChars = null,

I assumed that would show me the same thing as tracing the values? I tried the trace thing and now my code reads:
[AS]
//Build html to go in text field from the two arrays that are built from the database
//where count is the index of the values that we are on
Services_str = “”+Services_array[count]+"";
Services_mc.Services_text_mc.Services_txt.html = true;
Services_mc.Services_text_mc.Services_txt.htmlText = Services_str;

trace(Services_mc.Services_text_mc.Services_txt.textWidth);
trace(Services_mc.Services_text_mc.Services_txt.textHeight);
//Move the text feild to a random position on the stage, but make
//sure that the entire text will fit
Services_mc._x = Math.random() * (Scene_Width - Services_mc.Services_text_mc.Services_txt.textWidth);
Services_mc._y = Math.random() * (Scene_Height - Services_mc.Services_text_mc.Services_txt.textHeight);
[/AS]
When I test the movie all I see is 0’s, and when I do a “Variables List” I see


Level #0:
Variable _level0.$version = "WIN 6,0,21,0"
Variable _level0.Services = "Service 1,Service 2,Service 3,Service 4,Service 5"
Variable _level0.services_links = "1,2,3,4,5"
Variable _level0.status = "1"
Variable _level0.Services_array = [object #1, class 'Array'] [
    0:"Service 1",
    1:"Service 2",
    2:"Service 3",
    3:"Service 4",
    4:"Service 5"
  ]
Variable _level0.Services_Links_array = [object #2, class 'Array'] [
    0:"1",
    1:"2",
    2:"3",
    3:"4",
    4:"5"
  ]
Variable _level0.Scene_Width = 483
Variable _level0.Scene_Height = 115
Variable _level0.count = 0
Variable _level0.Services_str = "<a href='1'>Service 1</a>"
Movie Clip: Target="_level0.Services_mc"
Movie Clip: Target="_level0.Services_mc.Services_text_mc"
Variable _level0.Services_mc.Services_text_mc.Services_text = "Services"
Edit Text: Target="_level0.Services_mc.Services_text_mc.Services_txt"
    variable = "Services_text",
    text = "Services",
    htmlText = "<P ALIGN=\"LEFT\"><FONT FACE=\"Arial\" SIZE=\"25\" COLOR=\"#F4F4F4\">Services</FONT></P>",
    html = true, textWidth = 0, textHeight = 0, maxChars = null,
    borderColor = 0x000000, backgroundColor = 0xFFFFFF, textColor = 0xF4F4F4, border = false,
    background = false, wordWrap = false, password = false, multiline = false,
    selectable = false, scroll = 1, hscroll = 0, maxscroll = 1,
    maxhscroll = 0, bottomScroll = 1,
    type = "dynamic",
    embedFonts = true, restrict = null, length = 8, tabIndex = undefined,
    autoSize = "none",
    condenseWhite = false

Now line 31 of this listing shows


html = true, textWidth = 0, textHeight = 0, maxChars = null,

I think the reason that the textHeight now reads 0 instead of 2 is because I changed the Line Spacing from 2 to 0 since I made the first post.

sorry… didn’t read that piece of code!

and are you using the code to create the text fields only after the variables that come from the db load?
make sure you are!

your last piece of code doesn’t have the “a” tag but the previous one did.

Yes I am sure that the db loads first. All of the above code is in frame 3, and in frame 2 I have[AS]//Look for a way to test the number of times the loop back to frame 1
//has been doen so that we can set a time out. Additionally, maybe put
//logic in the system to test for a blank services?
if (_root.status == 1) {
Services_array = Services.split(",");
Services_Links_array = Services_Links.split(",");

//Need to get this value here, because the size is returned with any
//part hanging off the sides, so the text box could be off the end
Scene_Width = _root._width;
Scene_Height = _root._height;

count = 0;
gotoAndPlay(3);

} else {
gotoAndPlay(1);
}[/AS]and in frame one I have:[AS]//loadVariablesNum(“default.asp?flash=services”, 0);
//Use file for testing, put point to actual asp script
//when publish
loadVariablesNum(“services.txt”, 0);[/AS]Additionally, the List Variables shows the variables are split up, so they must be loaded. I have attached my current fla file incasethat would help.

Thanks,
Jimmy Puckett

I would never get there without the fla.

select the text box
click the html icon in the properties panel
click the character icon, select none

to embed the font you need to use action script, I think…
you have already htm=true, so you don’t need it again in the propertie panel

I have the HTML icon selected already, and the reason that I am embeding the fonts is to allow the tweens to work. I thought that the fonts had to be embeded to allow tweening of dynamic text to work?

Thanks,
Jimmy Puckett