DISQUS

circlecube - interactive actionscript: ColorTransform | RGB, Hex and random colors | Actionscript Color Tutorial

  • Phil · 1 year ago
    This is great - need to convert this to as3 though. I assume it will largely be the same?
  • ainhoitxu · 1 year ago
    I tried this code and it completely colors my movieclip. How do you keep the borders with their original color (in your case white)? In your example only the inside of the circle changes color, not the borders.

    Thanks!
  • circlecube · 1 year ago
    @Phil - I haven't messed with this in AS3 as of yet, but I will soon and I'll be sure to post about it.

    @ainhoitxu - Simple really, in my example I have a movieclip containing two more clips, the inner part of the circle and the outline. Thay are seperate clips, and in the setColor(colorBall.inner, theColor); function I am sendning as an argument the colorBall.inner movieClip. I could also send in the colorBall.outline to change the color of the stroke, or like you have done and send in the whole clip as one. Make sense?
  • ainhoitxu · 1 year ago
    It does totally make sense! I am trying to do the same as you, color the inner part of an image with borders. I suppose there is no easier way to do it than having 2 different movieclips, right?
  • Isaac · 11 months ago
    Is this really the bare minimum of what's required to program a color change in flash? Basically... I have a movieclip in my library, and I have a command that will call that out and place it on stage, but for each time it's loaded onto the stage, I want it to randomize its color. I've been trying to insert code to do this in the "function onLoad () { }" segment, but I don't seem to understand how to get the colorTransform code to work on an already existing movie clip. I keep finding examples that involve creating objects from code...
  • jive · 9 months ago
    Isaac, this is the bare minimum to transform a movieclip with an instance name of "mymc"
    ---

    import flash.geom.ColorTransform;
    import flash.geom.Transform;

    var myTransform:Transform = new Transform(mymc);
    var myColorTransform:ColorTransform = new ColorTransform();
    myColorTransform.rgb = 0xFF0000;
    myTransform.colorTransform = myColorTransform;
  • robert · 9 months ago
    To my knowledge this is the only post that actually shows how to convert hex to RGB. Thank you very much. It works well for me.
  • Gabriel · 7 months ago
    This is great, but I can't make it work. I just needed a code which could transform separated R, G, and B values into one RGB value. But when I use your rgb2hex function and I give in 0xFF, 0xFF, 0xFF, then it fills my rectangle with red color instead of white.
    Do you know why this happens? (I use _ to make the code more readable, they're not in my AS file.)
    colorBitmapData = new BitmapData(256, 256, false);

    for (var i=0; i<256; i++) { ___for (var j=0; j<256; j++) {
    ______hex = rgb2Hex(0xFF, 0xFF, 0xFF);
    ______rect = new Rectangle(j, i, 1, 1);
    ______colorBitmapData.fillRect(rect, hex);
    ___};
    };

    private function rgb2Hex(r, g, b):Number {
    ___return (r<<16 || g<<8 || b);
    };

    I'm actually trying to create a gradient filled box which has 2 black corners, 1 white corner and 1 corner with a specified color value. But I don't seem to manage the colors good enough even for a solid fill...
  • Gabriel · 7 months ago
    Alright, I was pretty stupid with this. I forgot to add the r, g, b values to each other to get the total RGB value...
  • Eduardo F. Sandino · 7 months ago
    Hi... Really thanks... Evan , i don't know what were developers of AS3 thinking when not puting a HEX conversor in the flash libraries... but you solve it, almost i reinvent the wheel... But you solved this commnon issue... thanks..