A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Is there some way to create custom color variable?

  1. #1
    Junior Member
    Join Date
    Oct 2007
    Posts
    22

    Is there some way to create custom color variable?

    I'm creating a fairly complex animation frame-by-frame, but I would like to be able to change the color of certain parts of it dynamically. The only approach I can think of is changing each section into a movieclip, putting them all into an array and then looping through the array and assigning a color. However, the animation is long and since the colored shapes constantly change, I would end up with more than a hundred MCs.

    A better option, if possible, would be to create a custom variable that I assign as a color in the color picker. So, instead of choosing a value like "#CCCCCC", I would be able to assign a name like "customColor", then I would dynamically change the value of "customColor" in AS3. Is that at all possible? Do you know of any extensions that add that functionallity?

  2. #2
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    I'd love to see that. I remember hearing about it in InDesign CS3 (which I don't have), but I don't believe it's in the other CS3 applications.

  3. #3
    Junior Member
    Join Date
    Oct 2007
    Posts
    22
    I've found nothing so far, so I'm considering trying to build my own panel/extension for it. Not sure how hard it would be though...

  4. #4
    Palindrome emordnilaP Diniden's Avatar
    Join Date
    Feb 2008
    Posts
    230
    Are you trying to accomplish something like this:

    geocities.com/dr_baboom/UniversalTileEditor.html

    (click a plus sign in the library panel then select the box next to it to see what I'm talking about)

    I did that color box dynamically

  5. #5
    Junior Member
    Join Date
    Oct 2007
    Posts
    22
    Hmmm....maybe? I had a bit of trouble figuring out how to work that application, but I think I got the gist of it. What I mean is a bit different - basically I'd like to be able to "paint by numbers".

    Let's say I draw/animate a fairly complex scene in Flash and I don't want to cut up each individual color area into movieclips (which is one way to do this). Instead I have a custom panel, but when I am assigning a fill/stroke color, instead of choosing an actual color I can create a new "color variable" or assign a pre-existing one, like "backgroundColor" or "skinTone", etc.

    Then in the same panel, I can at any point choose one of the variables and assign it an actual color value - and all the objects with that variable as their stroke/fill will change to the new color.

    Finally, I can also dynamically change the value of that variable in AS3 and the color would change at runtime.

  6. #6
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    Basically he wants a color pallet.
    .

  7. #7
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    I found this in the help file of Flash:

    PHP Code:
    package 
    {
        
    import fl.controls.ColorPicker;
        
    import fl.controls.ComboBox;
        
    import flash.display.BlendMode;
        
    import flash.display.Shape;
        
    import flash.display.Sprite;
        
    import flash.events.*;
        
        public class 
    ColorPickerExample extends Sprite
        
    {
            var 
    circle1:Shape;
            var 
    circle2:Shape;
            var 
    circle3:Shape;
            
            public function 
    ColorPickerExample():void {
                
    setupCircles();
                
    setupComboBox();
                
                
    cp1.addEventListener(Event.RENDERcolorChange);
                
    cp2.addEventListener(Event.RENDERcolorChange);
                
    cp3.addEventListener(Event.RENDERcolorChange);
            }
            private function 
    colorChange(e:Event):void {
                var 
    cp:ColorPicker e.target as ColorPicker
                
    switch (cp) {
                    case 
    cp1:
                        
    colorCircle(circle1cp.selectedColor);
                        break;
                    case 
    cp2:
                        
    colorCircle(circle2cp.selectedColor);
                        break;
                    case 
    cp3:
                        
    colorCircle(circle3cp.selectedColor);
                        break;
                    default:
                        break;
                }
            }
            private function 
    setupComboBox():void {
                
    cb.setSize(150,24);
                
    cb.addItem( { label"Select BlendMode:",     data:BlendMode.NORMAL } );
                
    cb.addItem( { label"DARKEN",                 data:BlendMode.DARKEN } );
                
    cb.addItem( { label"DIFFERENCE",             data:BlendMode.DIFFERENCE } );
                
    cb.addItem( { label"HARDLIGHT",             data:BlendMode.HARDLIGHT } );
                
    cb.addItem( { label"INVERT",                 data:BlendMode.INVERT } );
                
    cb.addItem( { label"LAYER",                 data:BlendMode.LAYER } );
                
    cb.addItem( { label"MULTIPLY",             data:BlendMode.MULTIPLY } );
                
    cb.addItem( { label"SUBTRACT",             data:BlendMode.SUBTRACT } );
                
    cb.addEventListener(Event.CHANGE,blendChange);
            }
            private function 
    blendChange(e:Event):void {
                var 
    newBlend:String cb.selectedItem.data;
                if (
    newBlend) {
                    
    circle1.blendMode newBlend;
                    
    circle2.blendMode newBlend;
                    
    circle3.blendMode newBlend;
                }
            }
            private function 
    setupCircles():void {
                
    circle1 = new Shape();
                
    circle2 = new Shape();
                
    circle3 = new Shape();
                
                
    circle1.127;
                
    circle1.64;
                
    circle2.87;
                
    circle2.130;
                
    circle3.164;
                
    circle3.130;
                
                
    colorCircle(circle10xFF0000);
                
    colorCircle(circle20xFF0000);
                
    colorCircle(circle30xFF0000);
                
                
    addChild(circle1);
                
    addChild(circle2);
                
    addChild(circle3);
            }
            private function 
    colorCircle(circle:ShapenewColor:uint):void {
                
    circle.graphics.clear();
                
    circle.graphics.beginFill(newColor1);
                
    circle.graphics.drawCircle(0050);
                
    circle.graphics.endFill();    
            }
        }

    It might not be the exact thing but it's a good start and by understanding how this works, the only thing left to do is to define a color palette. Not sure how to take at that one now, but if you sit down and plan a bit, I'm sure you'll find a way.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  8. #8
    Junior Member
    Join Date
    Oct 2007
    Posts
    22
    Nice, thanks- that gives me a good start with how color is assigned. I'm going to read about custom panel creation and see where I get - I'll post back with any results.

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