A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [F8] Hot to let User Change Font Color?

  1. #1
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392

    [F8] Hot to let User Change Font Color?

    I have a little project here and I want the text to be readable by everyone.

    As this is a game-esque type of project the Font style needs to be a certain way, so I can't alter that. However I did some testing with a group and found that the style is fine if the user can change their font color. Some see blues better, some reds, etc...

    So what I would like is to have a menu screen (done) with some example text (done) and a forward and/or back button (done). I would like the test font to change colors based on the user pressing the buttons(not done). When they find one they like and can read, they can click the save button (not done) and go on to the rest of the project, with their color still showing on the font.

    My ideas so far have been to create keyframes of the font for each color (tedious) and cycle through them with the buttons.

    I am hoping there is an all AS way of doing the color changes. I also would like some advice on saving these settings for the duration of the project.

    Thanks!

    ~MoN
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

  2. #2
    Ryan Thomson EvolveDesigns's Avatar
    Join Date
    Oct 2001
    Location
    British Columbia
    Posts
    3,338
    you would have to dynamically create your text fields then contol them using TextFormat. Here's a snippet from the flash help files for createTextField.

    Code:
    this.createTextField("my_txt", 1, 100, 100, 300, 100);
    my_txt.multiline = true;
    my_txt.wordWrap = true;
    var my_fmt:TextFormat = new TextFormat();
    my_fmt.color = 0xFF0000;
    my_fmt.underline = true;
    my_txt.text = "This is my first test field object text.";
    my_txt.setTextFormat(my_fmt);
    ps to the best of my knowledge TextFormat only works on actionscript created text field like the code above, but i've never tried applying it to a textfield made in the work area so it may work that way too.

    good luck!
    Evolve Designs Interactive Media
    the natural selection

  3. #3
    Banned
    Join Date
    Mar 2007
    Location
    Albania , prishtina
    Posts
    274
    i Think , It works and in textfield made in the work area .

  4. #4
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    Thanks guys! I now at least have a place to start! I will work somethings out and do some testing and see what I can come up with!

    Thanks again!

    ~MoN
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    also a quick and dirty way to change font color without using the textformat object:

    Code:
    var mc:MovieClip = this.createEmptyMovieClip("textholder", 1);
    mc.createTextField("tMessage", 1, 0, 0, 0, 0);
    mc.tMessage.autoSize = true;
    mc.tMessage.text = "hello";
    
    new Color(mc).setRGB(0xFF0000); // put whatever color u like in here
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  6. #6
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    Thanks for the input silentweed! If I were to do that, would I have to create the holder MC?

    My goal is to have an array of colors, my array building isn't up to snuff, but say something like:

    newArray = colorArray[0xFF0000, 0x000000, 0xFFCCCC, 0xCCCCCC, 0xCCCC00, 0xFFFFFF];

    Then I have a little arrow button on the stage below the text field. have something like this on it:

    Code:
    on (release) {
         for (i, i=0, i>6, +ii){
              my_txt.color = colorArray+i;
              };
    }
    I know that code and the for loop isn't correct, just putting something there and I don't know arrays and for loops very well yet... but you get the idea.. the user clicks the arrow and the text color cycles through the colors in the array.

    Ideas on that one?

    ~MoN
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

  7. #7
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    hi dont use a loop (as the screen doesnt refresh on loop iterations) .. use a setInterval or onEnter frame

    so for e.g suppose you have a button on stage with instance name "btn" then the following will loop through all the colors in the array;

    Code:
    var delay:Number = 0.5; //delay in seconds between color changes
    var nInterval:Number;
    var index:Number = 0;
    
    var aColors:Array = [0xFF0000, 0x000000, 0xFFCCCC, 0xCCCCCC, 0xCCCC00, 0xFFFFFF];
    
    var mc:MovieClip = this.createEmptyMovieClip("textholder", 1);
    mc.createTextField("tMessage", 1, 0, 0, 0, 0);
    mc.tMessage.autoSize = true;
    mc.tMessage.text = "hello";
    
    function color():Void{
     new Color(mc).setRGB(aColors[index]);	
     if(index == aColors.length - 1) clearInterval(nInterval); 
     index++;
    }
    
    btn.onRelease = function():Void{
     index = 0;
     clear(nInterval);
     nInterval = setInterval(color, delay*1000);	
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  8. #8
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    Thank you again silentweed. That is pretty close. Instead of looping through all the colors like that I just want it to go through them one by one, like on release of "btn" it goes to black, click again it turns red, click once more it turns yellow, then orange, then green, then back to the first one black.

    But thanks to you and the other posters I have quite a bit to work with and I am sure that with my limited knowledge I can make something work that I am after

    ~MoN

    P.S. I just noticed the title says "Hot" it should say "How" I swear I checked that! Oh well..
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

  9. #9
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    np yw ... to do what u need u just need to not use an interval e.g aprt from that it is more or less exactly as the above code

    Code:
    var index:Number = 0;
    
    var aColors:Array = [0xFF0000, 0x000000, 0xFFCCCC, 0xCCCCCC, 0xCCCC00, 0xFFFFFF];
    
    var mc:MovieClip = this.createEmptyMovieClip("textholder", 1);
    mc.createTextField("tMessage", 1, 0, 0, 0, 0);
    mc.tMessage.autoSize = true;
    mc.tMessage.text = "hello";
    
    function changeColor():Void{
     new Color(mc).setRGB(aColors[index]);	
     if(index == aColors.length - 1){ 
    	 index = 0;
    	 return;
     }
     index++;
    }
    
    btn.onRelease = function():Void{
     changeColor();
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  10. #10
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    Alright I will give that a spin and see what I end up with!

    Thanks for the insight! I swear one day I will get a grip on all this AS stuff...

    ~MoN
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

  11. #11
    Junior Member
    Join Date
    May 2007
    Posts
    26
    check if this link could be of any help

    http://www.codelinkers.com/2007/05/17/using-css-styles/

  12. #12
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    Thanks for the link! More knowledge is always good!


    ~MoN
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

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