A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] How to apply basic text formatting to textField / XML loaded info

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    30

    resolved [RESOLVED] How to apply basic text formatting to textField / XML loaded info

    Hi everyone,
    I'm workin' on a cool project for school. I'm loading up some text from an external XML doc, and bringing it in to a flash textField.

    It's working great, but I want to do a little formatting, first off, apply a bold tag or a bold font to some headings.

    Here's the .text field as I have it now:

    Actionscript Code:
    motorcycleInfo.text = "Make: " +
    bikeMaker[evt.target.selectedIndex] + "\n" + "MSRP: " +
    bikeCost[evt.target.selectedIndex] + "\n"
    + "Ride Category: " + bikeCategory[evt.target.selectedIndex] + "\n" +
    "Engine Size:
    <yadda yadda> etc...

    I've created a textFormat scheme for the motorcycleInfo textField and it is displaying correctly there. But setting the .bold element to true makes ALL the text of that textFormat bold. I just want some elements of the text to be bold, and I'd like to be able to do it on the fly, if it's possible.

    You see that it shows up as:
    Make: Kawasaki
    MSRP: $14,999
    etc... but I'd like for it to show up as
    Make: Kawasaki
    MSRP: $14,999
    etc...

    It's viewable here.

    I've essentially hand-typed "Make", "MSRP" and all the headings ... is there a way to simply turn on a bold text effect within my existing code?

    Thank you


    (ps I finally figured out how to wire up my mp3's so they play, and pause, I just haven't loaded that swf up to my server... so if you press the music buttons and they don't play, that's the reason.)

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Just use htmlText instead of .text and wrap the words in bold tags.
    Actionscript Code:
    motorcycleInfo.htmlText = "<b>Make: </b>" +

    Here are the other tags you can use.
    http://help.adobe.com/en_US/AS3LCR/F....html#htmlText

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    30
    Thanks jAquan, that indeed worked. I had tried that before, but this time I remembered that in the TextFormat I specifically set the bold property to be false. Then, of course, it wouldn't go bold. I removed that property and it works!

    Now... how would I go about inserting a hyperlink, using as the hyperlink one of my XML properties (motorcycle link="http://hondamotorcycles.com")

    The help page you recommended discusses this:
    To specify a link event, use the event scheme instead of the http scheme in your href attribute. An example is href="event:myText" instead of href="http://myURL"; when the user clicks a hypertext link that contains the event scheme, the text field dispatches a link TextEvent with its text property set to "myText".

    I don't understand 'zactly how to implement it... Where would the actual URL address be? And how would my anchor text be hyperlinked using the URL in my textField?

  4. #4
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Yeah TextFormat objects are great when you want to apply that style to an entire TextField but quickly become difficult when you have specific portions of text. When mixed formatting is required I prefer StyleSheet objects.

    As far as links go, if you just want to navigate to a different url, you write it just as you would in html.

    Say motorcycle.link pointed to the address, you'd just concatenate that value within an a tag. Properties within a bracket are called attributes and they have to be enclosed in single or double quotes. Since the string being assigned to .htmlText is already enclosed in quotation marks, you just have to use other kind or escaped quotes when quotes are needed as part of the string. In an a tag, 'href' is an attribute whose value needs quotes, so we'll use double quotes for the string, single quotes for the attribute.
    Actionscript Code:
    cycleInfo.htmlText = "<a href='" + motorcycle.link + "'>The text for this link</a>"

    this will result in:
    Actionscript Code:
    <a href='http://hondamotorcycles.com'>The text for this link</a>

  5. #5
    Member
    Join Date
    Mar 2010
    Posts
    30

    Thumbs up Thanks again!

    Yep, jAquan, it works terrific. I doubt that I would have gotten around to that combination of quotation marks and structure myself in a month.

    Thanks very much for your assistance!


  6. #6
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    You're welcome. Just so you know, if for some reason you need to use double quotes inside of an already double quoted string, you can "escape" them with a \.
    So this would produce the same result.
    Actionscript Code:
    cycleInfo.htmlText = "<a href=\"" + motorcycle.link + "\">The text for this link</a>"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center