7 Replies Latest reply on Apr 29, 2008 10:51 PM by kglad

    how can i apply gradient...

    Ashi_k Level 1
      I have a rectangular shape movie Clip (Size :130px X40 px). I want to apply linear gradient on it using action script. Can anybody help me how can I apply gradient on it.

      Note: This movie clip is made manually. Not by using createEmptyMovieClip method.
        • 1. Re: how can i apply gradient...
          kglad Adobe Community Professional & MVP
          check the beginGradientFill() method of movieclips.
          • 2. how can i apply gradient...
            Ashi_k Level 1
            i already checked this -

            MAKE A OVAL ON YOUR STAGE AND GIVE THIS INSTANCE NAME 'ovl' (withought single quote) and use the code under //**********************

            here i am creating two movie clips on stage --

            1st is 'ovl' and 2nd one is 'mc'

            But to apply gradient on ovl i have to use setMask method like this _root.mc.setMask(_root.ovl)
            i do not want to use SetMask... I want to apply gradient directly on 'ovl'

            How can i do ??????????????



            //**********************
            // create emtpy movieclip
            mc = createEmptyMovieClip("mc",1);
            // set the constants for the gradient fill
            // the colors
            col = [0x000066,0x0033FF];
            // the alphas
            alp = [100,30];
            // the ratios
            rat = [100,255];
            //
            //this.onMouseMove = function () {
            // we will make a radial gradient
            // and make it move with the mouse
            //
            // first we clear the previous gradient fill
            mc.clear();
            //
            // get the mouse-position
            // the x-coordinate
            x = _xmouse-200;
            // the y-coordinate
            y = _ymouse-200;
            // set the matrix for the transformation
            matrix = { matrixType:"box",x:x,y:y,w:400,h:400,r:0 }
            //
            // now make the new gradient fill
            mc.beginGradientFill("linear",col,alp,rat,matrix);
            // now make the shape to fill
            mc.lineTo(400,0);
            mc.lineTo(400,400);
            mc.lineTo(0,400);
            // end the fill
            mc.endFill();
            //}
            _root.mc.setMask(_root.ovl) Text Text
            • 3. Re: how can i apply gradient...
              kglad Adobe Community Professional & MVP
              what does mc have to do with anything?
              • 4. Re: how can i apply gradient...
                Ashi_k Level 1
                see .. i have drawn a movie clip on stage using oval tool.. now i have converted it in movieclip symbol by pressing F8 function key, i gave it instance name ovl..

                Now i want to fill gradient in this .. how can i do. thats it
                • 5. Re: how can i apply gradient...
                  kglad Adobe Community Professional & MVP
                  there's no easy way using actionscript for a non-rectangular shape. you have to use the bitmapdata class.
                  • 6. Re: how can i apply gradient...
                    Ashi_k Level 1
                    Can u give me some code hint. which method of bitmapdata class should i use.
                    • 7. Re: how can i apply gradient...
                      kglad Adobe Community Professional & MVP
                      the key method is the merge method with r,g,b multiplier = 256.