A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: blend colors

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    166

    blend colors

    I have 2 mc's on stage, - one is draggable and has an alpha of 50 %.

    My code in frame 1 is:

    // instance of the color object
    squareColor = new Color("red_mc");
    squareColor.setRGB("0xFF0000");

    // events on red_mc
    red_mc.onPress = function(){

    this.startDrag();
    trace("color = "+squareColor.getRGB());

    }

    red_mc.onRelease = function(){

    this.stopDrag();

    }

    So now I wonder if there's any way I can get the color value for the color I get when I drag red_mc over my 2. mc, - I mean if mc1 is green and mc2 is red, - the result would be a dark red, - but how do I get that value at runtime?


    Kind regards

    Godowsky




  2. #2
    Senior Member dipkya's Avatar
    Join Date
    Mar 2001
    Location
    Mumbai (India)
    Posts
    158
    To get RGB:

    function CreatColor () {
    c = new Color("dm");
    r = (Math.random()*256);
    g = (Math.random()*256);
    b = (Math.random()*256);
    c.setRGB(r << 16 | g << 8 | b);
    _root.hexValue="#"+(c.getRGB()).toString(16);
    trace(_root.hexValue)
    }

    onMouseDown=function(){
    CreatColor()
    }
    dipkya
    ---------------------------------------------------------------
    SO MUCH HAVE TO DO, SO LITTLE HAS DONE!

  3. #3
    Senior Member
    Join Date
    Jan 2001
    Posts
    166
    As far as I can see from that code it just makes a mc have a random color each time you press the button, - and that's not my problem, - I want to receive the color code from the color that is beeing generated when a mc with one color (red) and an alpha (fx. 50%) is dragged over another mc with another color (green), - it's, in this case, a dark red color, - how can I get this code via actionscript?


    Kind regards

    Godowsky

  4. #4
    Senior Member dipkya's Avatar
    Join Date
    Mar 2001
    Location
    Mumbai (India)
    Posts
    158
    Check the code again
    ====================================
    _root.hexValue="#"+(c.getRGB()).toString(16);
    trace(_root.hexValue)
    =====================================
    Above lines give you hex values of movieClip color

    If want to know color with alpha property then you should myColor.getTransform() instead getRGB

    regards
    Last edited by dipkya; 08-25-2004 at 02:15 AM.
    dipkya
    ---------------------------------------------------------------
    SO MUCH HAVE TO DO, SO LITTLE HAS DONE!

  5. #5
    Senior Member
    Join Date
    Jan 2001
    Posts
    166
    Hi, - the problem is not to get the color of an mc with an alpha, - the problem is getting the color that is created when a mc with an alpha is over another mc, - mc1 is fx. red with an alpha 50% and mc2 is fx. green.

    When I take mc1 and drag it over mc2 I get a 'new' color, - the blending of the transparent red and the solid green, - in this case a dark red, - that is the color code I want, - but the problem is that this color is neither the red or the green mc's color but a blend of both and how do I address this mc1mc2 movieClip ;-)

    Kind regards


    Godowsky

  6. #6
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    I am pretty sure that the color you are supposed to get from mixing yellow and blue is green, and not grey.

    However, in strict bitwise terms, this does what you want more or less ... and in any case, was a bit of fun putting together.

  7. #7
    Senior Member
    Join Date
    Jan 2001
    Posts
    166
    Looks great, but I'm not sure I understand, - I send a very simple sample of what it is I'm after, - just drag the red square into the green circle and give me the blended color, - I will be the happiest man on earth ;-)
    Attached Files Attached Files

  8. #8
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    I can't open MX 04, but this cuts out a lot of the faffing about.

  9. #9
    Senior Member
    Join Date
    Jan 2001
    Posts
    166
    Here's another version, -flash mx.

    Your last sample didn't seem to work on my machine, - only some white circles and boxes...

    Best regards

    Godowsky
    Attached Files Attached Files

  10. #10
    Senior Member
    Join Date
    Jan 2001
    Posts
    166
    sorry man, - was in the wrong mode, - now it works, - yes I think we are getting closer here... I'll check it out and return later, - thanks a lot for your help.


    Godowsky

  11. #11
    Senior Member
    Join Date
    Jan 2001
    Posts
    166
    Still I have a problem, - what if my dragging square is moved over an image... I know that I can't get any colors out of an image in flash, - but If my drag mc has an alpha, - can I then get the value.

    Lets say its a black and white image, - so I only want to let my drag mc aware if it's over something white og something black in the image.

    We can make it as simple as a image of a black line on white background.

    So if I take my drag mc with an alpha an move over the image, - I should have a darker red when moving over the black line.

    So you see, - is it possible to get the color of this blend? I mean the color of the part of my drag mc that is over the black line.
    Kind regards

    Godowsky
    Attached Files Attached Files

  12. #12
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    You can only use the Color object to access information from Color objects.

    eg: getRGB will only get the RGB for a MC that has had RGB or transform set by a Color object. Similarly, getTransform will only get the transform set by a Color object.

    You should be able to modify my example to use get/setTransform rather than get/setRGB. This would allow you to use alpha values. So the next problem is how to do the stripes.

    Color objects apply to an entire MC. Therefore, for each separate alpha setting you want, you need a separate MC.

    If you break the stripe down into five(?) MC (three white and two black) you can do what you want.

  13. #13
    Senior Member
    Join Date
    Jan 2001
    Posts
    166
    thankx for your question, - sorry to say that manipulating the jpeg is out of the question, - so no 5 mc's ;-)


    But I just got this idear, - if my draggable mc is 1x1 pixcel and I drag it over my jpeg, my whole drag mc (with the alpha) has a new color, - I mean it's not the jpeg that has a new color it's the drag mc and it's not just part of the mc but the whole thing..


    Well, - just an idear ;-)

    Kind regards

    Godowsky

  14. #14
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    Flash doesn't allow you to query the colour of individual pixels. The colour blending isn't necessarily the colour you see on screen, but is the result of a mathematical operation on two colour transforms.

    For example, if you have an MC set using Color to be red with _alpha of 20; it may appear to be something quite different while dragging over a brightly coloured JPEG. However, for the purposes of the mathematic comparison, it will still think of itself as red and 20% _alpha.

  15. #15
    Senior Member
    Join Date
    Jan 2001
    Posts
    166
    ok, - so there's no way of getting the code for that blend color.

    Thanks.


    Kind regards


    Godowsky

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