A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Change text color of dynamic text

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    26

    Talking Change text color of dynamic text

    i need some help with colors
    the codes that i found dont seem to work for me
    heres my code setup

    frame 2:
    randomizer = random(2)
    if 0 { some = "something"
    if 1 { another = "yetanother"
    frame 3:
    2 dynamic text fields with some/another typed in there variables
    output: something/yetanother in black

    i now want to add color, say white for "something" and red for "yetanother"
    <instance name> i filled box 1 with "somethingc" and box 2 with "anotherc"

    i tryed the following

    if 0 { some = "something"
    somethingc.textColor = 0xFFFFFF
    if 1 { another = "yetanother"
    anotherc.textColor = 0xFF0000

    with and without _root.
    and...

    frame1:
    normalText = new TextFormat();
    normalText.color = 0x000000;
    clickText = new TextFormat();
    clickText.color = 0xFF0000;
    myTextBox.text = "This is the test text";
    myTextBox.setTextFormat(normalText);

    changed to

    normalText = new TextFormat();
    normalText.color = 0x000000;
    clickText = new TextFormat();
    clickText.color = 0xFF0000;
    somethingc.text = "This is the test text"; <---but but...i dont wanna change mah text? i have a variable for that..???
    somethingc.setTextFormat(normalText);
    frame2:
    _root.somethingc.setTextFormat(_root.clickText);

    doesnt work in any way i tryed them

    helpies!
    Last edited by Kascas; 03-22-2014 at 12:28 PM.

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    function randomizer(num:Number)
    {
    num = Math.round(Math.random() * num + 0);
    trace(num);
    if(num == 0)
    {
    some.text = "something";
    some.textColor = 0xFFFFFF
    }
    if(num == 1)
    {
    another.text = "yetanother";
    another.textColor = 0xFF0000
    }
    }

    randomizer(1);
    This works if you have the dynamic textfields in the same frame of the randomizer function. And very important, you have to remove the variable of the dynamic textfields, and use instance names
    instead (same, another)
    Last edited by angelhdz; 03-22-2014 at 06:39 PM.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    26
    lets see if i can get this to work...

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    26
    it worked!...once
    well at least im happy i finely got color after 100 trys even if it doesnt work the right way yet

    i could realy use it on another frame, if possible
    and is there a reset function? i want to repeat it infinitely, after 1 try it turns back to default black

    is the function realy neccesairy? however you spell that
    cant i just like

    if(random == 1)
    {
    another.text = "yetanother";
    another.textColor = 0xFF0000
    }
    as easy as that?...doesnt seem to work

    edit is does work, yet only once, after i difined what it is once, i cant change it anymore.....
    Last edited by Kascas; 03-23-2014 at 08:02 AM.

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    What are you trying to do?
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    var randomizer:Number = Math.round(random(2));
    if(randomizer == 0)
    {
    some.text = "something";
    some.textColor = 0xFFFFFF
    }
    else if(randomizer == 1)
    {
    another.text = "yetanother";
    another.textColor = 0xFF0000
    }


    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  7. #7
    Junior Member
    Join Date
    May 2010
    Posts
    26
    Quote Originally Posted by angelhdz View Post
    What are you trying to do?
    alright, im making this game where you go from place to place and buy/sell resources along the way

    lets say on frame 1 are the general codes
    frame 2: the places
    frame 3: travel animation
    frame 4: randomizer(resources) -> gotoAndStop frame 2


    i have 6 differend resources and at every new place i use random(6)
    to generate the resource they are selling 3times
    and the same for buying 3times

    i dont exclude dubbles, so this is frame 4
    randomizer = random(6)
    if = 1 {sell1 = res 1} if = 2{sell1 = res2} etc etc
    randomizer = random(6)
    if = 1 {sell2 = res 1} if = 2{sell2 = res2}
    etc etc
    gotoAndStop("frame2")

    Output example:
    sell1 = resource4
    sell2 = resource4
    sell3 = resource2
    buy1 = resource4
    buy2 = resource1
    buy3= resource4

    I have an output on frame 2:
    Buying:
    res4
    res4
    res2
    Selling:
    res4
    res1
    res4

    i also added the current resources you own
    res1: 0
    res2: 0
    res3: 0
    res4: 0
    res5: 0
    res6: 0
    all in differend colors to easily spot what it is

    yet the problem is, that the buying/selling output is in black.
    it would make quickly matching what kinds you can buy/sell way easyer if those are colored aswell
    like hey its white! white is res1! or ooh everything is green, res3, i cant buy/sell green so lets continue
    way easyer then actualy reading the full name of res3 and then going throught your resource list to find the corresponding resource.

    i tryed your code pasted it on frame2 and it worked at first. res1 turned white
    but as soon i went to another frame and back, with unrelated things
    it was unable to recalculate that its white, and stayed black
    also after frame4 new generate, it stays black
    tryed several things, yet anything that worked so far seems to be unable to repeat
    Last edited by Kascas; 03-24-2014 at 09:34 AM.

  8. #8
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Please send the .fla so i can see clearly what you are trying to do, and that way i don't have to analize and imagine things.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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