A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Color (Hexadecimal)

  1. #1
    Member
    Join Date
    Jun 2000
    Posts
    50

    Color (Hexadecimal)

    Hello, I'm having trouble with the way hexadecimal colors show up on different platforms. It works perfectly on a pc but, it only shows up in blue tints on a pc. Here is the code which was geniusly created and graciously donated by Geoff Stearns@deconcept.com (http://www.deconcept.com)

    thanks for any help.

    Here is the code:

    This code that is on the movieclip that will chage color:

    onClipEvent (load) {
    var a = 15;
    // this is the speed of the transition, the higher the value, the slower the fade
    myColor = new Color (this);
    // this sets up the color object, and sets the other variables to the initial values
    var cRGB = myColor.getRGB ();
    var cHEX = cRGB.toString (16);
    var newRGB = cRGB;
    var newHEX = cHEX;
    }
    onClipEvent (enterFrame) {
    if (cHEX <> newHEX) {
    // break the hex into 3 values, one for each color
    var cHEX_r = parseInt (cHEX.substring (0, 2), 16);
    var newHEX_r = parseInt (newHEX.substring (0, 2), 16);
    var cHEX_g = parseInt (cHEX.substring (2, 4), 16);
    var newHEX_g = parseInt (newHEX.substring (2, 4), 16);
    var cHEX_b = parseInt (cHEX.substring (4, 6), 16);
    var newHEX_b = parseInt (newHEX.substring (4, 6), 16);
    // adjust each value independantly, so you don't get any wierd colors showing up
    // adjust red value
    if (cHEX_r <> newHEX_r) {
    var r_diff = Math.round ((newHEX_r - cHEX_r) / a);
    if (Math.abs (r_diff) < 1) {
    cHEX_r = newHEX_r;
    } else {
    cHEX_r += r_diff;
    }
    }
    // then green value
    if (cHEX_g <> newHEX_g) {
    var g_diff = Math.round ((newHEX_g - cHEX_g) / a);
    if (Math.abs (g_diff) < 1) {
    cHEX_g = newHEX_g;
    } else {
    cHEX_g += g_diff;
    }
    }
    // then blue value
    if (cHEX_b <> newHEX_b) {
    var b_diff = Math.round ((newHEX_b - cHEX_b) / a);
    if (Math.abs (b_diff) < 1) {
    cHEX_b = newHEX_b;
    } else {
    cHEX_b += b_diff;
    }
    }
    // adjust the color to the new value
    // sets the decimal numbers back to hex
    cHEX_r = cHEX_r.toString (16);
    cHEX_g = cHEX_g.toString (16);
    cHEX_b = cHEX_b.toString (16);
    // this check is needed if there is a 0 value in the string, when you use toString() it will leave 0's blank,
    // instead of filling them in, so you get "0" instead of "00" or "e" instead of "0e" so this fills in the 0
    // if it is needed
    while (cHEX_r.length < 2) {
    cHEX_r = "0" + cHEX_r;
    }
    while (cHEX_g.length < 2) {
    cHEX_g = "0" + cHEX_g;
    }
    while (cHEX_b.length < 2) {
    cHEX_b = "0" + cHEX_b;
    }
    // end toString() fix
    cHEX = cHEX_r + cHEX_g + cHEX_b;
    // set the current HEX variable
    myColor.setRGB (parseInt (cHEX, 16));
    // set the color of the BG (or object)
    }
    }


    This is the code that is on the button to chage the color of the movieclip:

    on (release) {
    _root.bg.newHEX = "000000";
    }

  2. #2
    Member
    Join Date
    Jun 2000
    Posts
    50

    Color(Hexadecimal)2

    I meant to say it works perfectly on a pc but only shows up as blue tints on a mac.

    thank you

  3. #3
    Senior Member
    Join Date
    Nov 2000
    Location
    Manchester, UK
    Posts
    454
    I've had a look at the code and it may be something to do with the initial colour setting of the BG clip.
    The first time I tried this it didn't work but after I'd set the bg clip's colour in the property inspector it worked fine.
    I added 3 other buttons and changed the var "_root.bg.newHEX" on each one.
    I also added a trace on the buttons to see what the current value of the RGB colour was.
    trace(_root.bg.myColor.getRGB().toString(16));
    Maybe if you try this on a mac you can see what's going on.
    I'm afraid I'm on a PC too so cannot replicate the problems you have.

    Hope this helps?

    Jon 8o)

  4. #4
    Member
    Join Date
    Jun 2000
    Posts
    50
    thank you I'll try it

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