Change text color at runtime

Ask a Question related to Macromedia Director Lingo, Design and Development.

  1. #1

    Default Change text color at runtime

    This must be a FAQ, but I can't find the answer anywhere. I can change
    the color of a text member's sprite at design time using the properties
    panel. Doing so changes only the sprite, not the color of the text
    member itself.

    How can I change the sprite's color in Lingo at runtime? I've tried
    setting the sprite's color and forecolor properties, to no avail.

    Gary Guest

  2. Similar Questions and Discussions

    1. change text color
      Is there anyway in acrobat, to open a pdf of many pages and globally change the color of all the text? Is there anyway to do this in any program...
    2. Can you change the color of text with the Touchup Text tool?
      I just want to say that your note helped me. I NEVER knew that I could use a right click to bring up properties when using the text touch-up tool!...
    3. How to change text color in 7 Pro?
      I am creating a PDF with many links. In 5 I would make the linked text blue so people would know it was a link. In 7 I could not do that, so I loaded...
    4. Does anyone know how to change the color of a text box?
      Does anyone know how to change the outline and fill of a text box in Flash? I only can change the font color that will be typed into the box. ...
    5. text color change in Flash MX
      I'm trying to change the color of my text on a rollover but it only changes on the edge of the text. Once I am over the text link, the color change...
  3. #2

    Default Re: Change text color at runtime

    Hi Gary,

    For text set the member's color using rgb values

    sprite(X)member.color = rgb(255,0,0)

    this will change the text color to red

    if you want to color only some part of the text, then specify the chunk
    to be changed:

    sprite(X)member.word[Y].color = rgb(0,255,0)

    --
    Rob
    _______
    Rob Dillon
    Team Macromedia
    [url]http://www.ddg-designs.com[/url]
    412-243-9119

    [url]http://www.macromedia.com/software/trial/[/url]
    Rob Dillon Guest

  4. #3

    Default Re: Change text color at runtime

    #1: This still doesn't work.

    #2: If I can change the color of the sprite (not the member) in the
    property inspector, why can't I do so in Lingo?


    Rob Dillon wrote:
    > Hi Gary,
    >
    > For text set the member's color using rgb values
    >
    > sprite(X)member.color = rgb(255,0,0)
    >
    > this will change the text color to red
    >
    > if you want to color only some part of the text, then specify the chunk
    > to be changed:
    >
    > sprite(X)member.word[Y].color = rgb(0,255,0)
    >
    Gary Guest

  5. #4

    Default Re: Change text color at runtime

    sprite(whichSprite).foreColor = colorConstant
    sprite(whichSprite).backColor = colorConstant

    works for me. This changes the color(s) of a sprite at runtime. The
    constants are exactly the ones which can be seen in the behavior inspector
    when changing the properties at design time (e.g. 255 for black or 0 for
    white). By the way, I've tried this with text members - don't know if it
    works with field members, maybe you're using a field member instead of a
    text member.

    If this doesn't work in your project, someting else is wrong as for me it
    always works.

    Bye,
    Loren Schwarz


    Loren Schwarz Guest

  6. #5

    Default Re: Change text color at runtime

    You said that you wanted to change the color of a text member's sprite.
    If this is a text member then that's the way that you change the text
    color. You can also use the foreColor property of the member.

    If the member is set to editable, and it's a text member, you can still
    change the text color, if it's a field, then the color will remain
    black.

    If you want to change the color of the background of the sprite and
    it's not set to editable, then you can set the backColor property of
    the member. If the member is set to be editable, then the backColor
    will remain white.

    You can't set the color of a text or field sprite, you have to set the
    member's property.

    --
    Rob
    _______
    Rob Dillon
    Team Macromedia
    [url]http://www.ddg-designs.com[/url]
    412-243-9119

    [url]http://www.macromedia.com/software/trial/[/url]
    Rob Dillon Guest

  7. #6

    Default Re: Change text color at runtime

    I know I'm new to this, but here's my thoughts:


    I'm not sure about sprite(x)member.color = .... I tried that and it didn't work - got a script error.

    Here's what works for me...

    member("x").color = rgb(x,x,x)
    member("x").forecolor = paletteIndexColor
    member("x").backcolor = rgb(x,x,x)
    sprite(x).forecolor = rgb(x,x,x)
    sprite(x).backcolor = rgb(x,x,x)
    sprite(x).color = rgb(x,x,x)


    My text sprites are usually set to "Not Copy", so the coloring convention is a little backwards and the sprite(x).(forecolor, backcolor, and color) functions don't seem to have any effect and if they do have an effect, it's opposite of what I tell it. So I use the member("x").color, backcolor, forecolor commands and those work for me. Albeit in reverse, but they work. Reverse meaning if I want white I use rgb(0,0,0) instead of rgb(255,255,255). Not sure why, but that's the way it's working for me.

    Here is the script I'm referring to:

    on mouseEnter me
    sprite(7).cursor = 280
    member("AutorunButton").color = rgb(58,40,20)
    end

    on mouseLeave me
    sprite(7).cursor = 0
    member("AutorunButton").color = rgb(0,0,0) --This shows white instead of black
    end

    on mouseUp me
    put "" into member("FAQ-List")
    member("AutorunButton").color = rgb(0,0,0) --This shows white instead of black
    member("FAQ-List").forecolor = 164 --Palette index color 164
    put member("autorun-text").text into member("FAQ-List")
    end


    Here's my interpretation - Changing the sprite color or member color is the same thing. One just refers to the placement in the score (spriteNum) and the other refers to the name you gave it in the cast list (member) - ie: member name. I'm not 100% about this, but so far I've had no trouble changing the colors of my text sprite's I use for links in my movie.

    It always seems that everyone has different methods of doing the same thing with the same programming language. Whether it's Lingo, ActionScript, C++ or what... always a different method depending on who you talk to. My advice would be to take the suggestions the other gents and I have given and experiment with it. Just open up the message window (ctrl+m) and start typing the commands. Something is bound to work at one point or another.

    Hope this helps,

    JKLea


    JKLea webforumsuser@macromedia.com Guest

  8. #7

    Default Re: Change text color at runtime

    sprite(x)member.color can't work because there is a dot missing:
    sprite(x).member.color. You are accessing the property "member" of the
    object "sprite(x)", that's why the full-stop is needed in between.

    The setting "not copy" per definition inverts any color. There is a page in
    Director help which explains all color effects, including this one. This is
    the reason for your rgb(0,0,0) resulting in white instead of black. You said
    your sprites are usually set to "not copy" - why don't you set them back to
    copy? :-) Handling would be easier...

    Sprites can be seen as instances of cast members. That is: when you change
    the color of a cast member, the color is changed in the "original" object,
    changes can be seen in all of its instances (sprites). Changing a sprite's
    color only changes the color of this one copy of the main object - leaving
    the "original" thing untouched. Even more, when you load a different member
    into the sprite you changed the color of, the newly loaded member will also
    appear in the sprite's color.

    Cheers
    Loren Schwarz


    Loren Schwarz Guest

  9. #8

    Default Re: Change text color at runtime

    Try this

    sprite(me.spriteNum).setVariable("buttonText.textC olor" , "0x009933")
    kideg Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139