as3 htmlText problem
Copy link to clipboard
Copied
I have a dynamic text box for 3 lines of text. I styled part of the text to be bold and part of it to be regular. When i click on the button to display the text it looks right the first time but if i click on it a second time then all of the text shows up bold instead of just the few lines i assigned the bold tag to. Has anyone else had this issue?
Copy link to clipboard
Copied
copy and paste the relevant (only) code.
Copy link to clipboard
Copied
I have the dynamic box properties set to Arial regular and then i'm adding the bold tag in actionscript window to the name and number. It looks fine the first time the button is clicked but second time it bolds everything. I am new to flash so no idea what i'm doing wrong ...
var alabama_btnInfo = "<b>John Smith<br>(555) 123-4567</b><br><font size=10>Northern Alabama</font><p>Mary Smith<br>(555) 123-4567<br>Southern Alabama</p>";
I am also having problems figuring out the leading. I would like there to be extra spacing between Northern Alabama text and Mary Smith text. I tried doing that in the properties window for the text box (since i dont know the code to do it myself) but it adds the same spacing for line breaks and paragraph breaks
Copy link to clipboard
Copied
1. you need to embed both fonts.
2. the code you showed doesn't match the image you showed.
3. show a typical state click listener and listener function where you assign your htmlText.
Copy link to clipboard
Copied
thanks kglad,
ok I embedded fonts and it's staying the way it should be but still can't figure out paragraph breaks and leading issue. Not even sure if the way i'm doing it is the best /most efficient way of creating this map?
here is all my code:
var alabama_btnInfo = "<b>John Smith<br>(555) 123-4567</b><br><font size=10>Northern Alabama</font><p><b>Mary Smith<br>(555) 123-4567</b><br><font size=10>Southern Alabama</font>";
var arizona_btnInfo= "<b>Your Name<br>(555) 123-4567</b><br><font size=10>Entire State of Arizona</font>"; and
alabama_btn.addEventListener(MouseEvent.CLICK, showInfo);
arizona_btn.addEventListener(MouseEvent.CLICK, showInfo);
function showInfo(evt:MouseEvent):void {
stateInfo.htmlText = this[evt.currentTarget.name+"Info"];
}
and here is what the map looks like now with the spacing issues when i click on alabama-
Copy link to clipboard
Copied
i'm not sure your code is doing anything because there are typos. use:
"<b>John Smith<br/>(555) 123-4567</b><br/><font size='10'>Northern Alabama</font><p>Mary Smith<br/>(555) 123-4567<br/>Southern Alabama</p>";
for leading, use the textformat class or stylesheets.
Copy link to clipboard
Copied
i fixed the typos in code. It is still making everything bold if i click on the state a second time- do i have to use some kind of font embed/import code instead of just telling it to embed within the properties panel?
i have no idea how to do text format- cannot figure out. Once i make a class somehow do i use a span tag?
Sorry for all the questions- i am trying to learn this on my own as much as possible but not having much luck- AS3 so confusing. Thank you for the help
Copy link to clipboard
Copied
function showInfo(evt:MouseEvent):void {
stateInfo.html=true;
stateInfo.htmlText = this[evt.currentTarget.name+"Info"];
}
<b>John Smith<br/>(555) 123-4567</b><br/><font size=10>Northern Alabama</font><br/><br/><b>Mary Smith<br>(555) 123-4567</b><br/><font size=10>Southern Alabama</font>
and you'r not closed the </p>.
If you still facing issues:
1. have a textbox out of the stage with the embedded font named (_txt) with render html enabled
2. _txt.text= this[evt.currentTarget.name+"Info"];
stateInfo.htmlText=_txt.text;
Copy link to clipboard
Copied
thank you relaxatraja,
when i added the stateInfo.html=true; it gave me an error so i took it out. This is the error mssg it was giving me: 1119: Access of possibly undefined property html through a reference with static type fl.text:TLFTextField.
Adding the extra <br/> did work to add space but i think i need to learn how to style lines individually to have more control over look. I very much appreciate the help- hopefully this will start to make sense soon
Copy link to clipboard
Copied
for the bold problem- i was wrong..it is still happening even after the fonts are embedded. The first 2 lines are bold and 3rd is regular the first time i click (the way it should be) but if i click on that same state again then all of the text goes bold?
Copy link to clipboard
Copied
if it helps this is what I'm trying to do. I have a map with each state as a button that has a rollover that changes the color of the state but i also have on mouse click display the text for that state. Name and number should be large and bold, area of state should be smaller and regular font face. Have been trying to figure this out forever now. Have basic html knowledge... i'm either doing something very wrong or the html code /tags i understand do not work for flash?
Copy link to clipboard
Copied
couldn't figure out how to make everything work with the current code so i changed my set up so that i have a regular text box with each state info in a different key frame and then on each state_btn i put a go to frame and stop action. Not sure if this is the proper or best way to do this but it is working so far- hopefully my file size won't be too large.
Copy link to clipboard
Copied
if your code is working, leave it.
Copy link to clipboard
Copied
it works fine as far as when i click on the state button the correct information shows up but i can't figure out / understand AS3 to customize the text to look like i want
Copy link to clipboard
Copied
you'll need to learn about the textformat class or style sheets to use features like variable leading (ie, different leading for different lines in the same textfield).
Copy link to clipboard
Copied
do you know a good site i can learn this? I'm on lynda.com right now looking thru tutorials
Copy link to clipboard
Copied
the flash help files are the best place to start for both of those. for example, check the textformat class. look for sample code that shows how to apply textformat instances (using setTextFormat) to different parts of your text.
textformat is easier to learn how to use than stylesheets. but because setTextFormat uses indices to determine where a textformat is applied, it's easier to apply style sheets.
Copy link to clipboard
Copied
thank you- i appreciate you taking the time to help
Copy link to clipboard
Copied
you're welcome.

