road0001 / tweener

Automatically exported from code.google.com/p/tweener
0 stars 0 forks source link

FIXED: _ColorTransform AS3 #16

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
To use color tranform in AS3 you must pass a colorTransform Object in the
tweener object

//------------
package  {

    //> Import Classes
    //-- -- -- -- -- -- -- -- -- -- --
    import flash.geom.ColorTransform;
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.MouseEvent;

    import caurina.transitions.Tweener;

    public class ColorTransformTest extends Sprite{

        //> Private Properties
        //-- -- -- -- -- -- -- -- -- -- --
        private var circle : Sprite;
        private var ct : ColorTransform;

        //> Public Properties
        //-- -- -- -- -- -- -- -- -- -- --

        //> Constructor
        //-- -- -- -- -- -- -- -- -- -- --
        public function ColorTransformTest() {
            circle = new Sprite();
            circle.x = stage.stageWidth/2;
            circle.y = stage.stageHeight/2;
            circle.graphics.beginFill(0x000000);
            circle.graphics.drawCircle(0,0,150);
            circle.graphics.endFill();
            addChild(circle);

            ct = circle.transform.colorTransform;
            trace(ct);

            addEventListener(MouseEvent.MOUSE_UP, changeColor)          
        }

        //> Private Methods
        //-- -- -- -- -- -- -- -- -- -- --
        private function changeColor(e:MouseEvent) : void {
            var newColor : uint = Math.random() * 0xFFFFFF;

            ct.color = newColor;
            trace(ct);

            Tweener.addTween(circle, {_colorTransform:ct, time:1,
transition:"easeOutExpo"});
        }

        //> Public Methods
        //-- -- -- -- -- -- -- -- -- -- --

    }
}
//-------------

also, You must edit caurina.transitions.SpecialPropertiesDefault.as

//--

//
--------------------------------------------------------------------------------
--------------------------------------------------
        // _colorTransform

        /**
         * Splits the _colorTransform parameter into specific color variables
         *
         * @param       p_value             Number      The original _colorTransform value
         * @return                          Array       An array containing the .name and .value of all
new properties
         */
        public static function _colorTransform_splitter (p_value:*):Array {
            var nArray:Array = new Array();
            if (p_value == null) {
                // No parameter passed, so just resets the color
                nArray.push({name:"_color_ra", value:1});
                nArray.push({name:"_color_rb", value:0});
                nArray.push({name:"_color_ga", value:1});
                nArray.push({name:"_color_gb", value:0});
                nArray.push({name:"_color_ba", value:1});
                nArray.push({name:"_color_bb", value:0});
            } else {
                // A color tinting is passed, so converts it to the object values
                if (p_value.redMultiplier != undefined) nArray.push({name:"_color_ra",
value:p_value.redMultiplier});
                if (p_value.redOffset != undefined) nArray.push({name:"_color_rb",
value:p_value.redOffset});
                if (p_value.blueMultiplier != undefined) nArray.push({name:"_color_ba",
value:p_value.blueMultiplier});
                if (p_value.blueOffset != undefined) nArray.push({name:"_color_bb",
value:p_value.blueOffset});
                if (p_value.greenMultiplier != undefined)
nArray.push({name:"_color_ga", value:p_value.greenMultiplier});
                if (p_value.greenOffset != undefined) nArray.push({name:"_color_gb",
value:p_value.greenOffset});
                if (p_value.alphaMultiplier != undefined)
nArray.push({name:"_color_aa", value:p_value.alphaMultiplier});
                if (p_value.alphaOffset != undefined) nArray.push({name:"_color_ab",
value:p_value.alphaOffset});
                /*
                if (p_value.ra != undefined) nArray.push({name:"_color_ra",
value:p_value.ra});
                if (p_value.rb != undefined) nArray.push({name:"_color_rb",
value:p_value.rb});
                if (p_value.ga != undefined) nArray.push({name:"_color_ba",
value:p_value.ba});
                if (p_value.gb != undefined) nArray.push({name:"_color_bb",
value:p_value.bb});
                if (p_value.ba != undefined) nArray.push({name:"_color_ga",
value:p_value.ga});
                if (p_value.bb != undefined) nArray.push({name:"_color_gb",
value:p_value.gb});
                if (p_value.aa != undefined) nArray.push({name:"_color_aa",
value:p_value.aa});
                if (p_value.ab != undefined) nArray.push({name:"_color_ab",
value:p_value.ab});
                */
            }
            return nArray;
        }

//--

Original issue reported on code.google.com by bugina...@gmail.com on 22 Aug 2007 at 5:08

GoogleCodeExporter commented 8 years ago
Thanks for this report.

But does that mean the _colorTransform special property wasn't working before? 
And
the aboce change fixes it?

I'll have a look at it.

Original comment by zisfor...@gmail.com on 22 Aug 2007 at 6:06

GoogleCodeExporter commented 8 years ago
ColorTransform object itself is different in AS3. It's properties now looks 
like redMultiplier/redOffset instead of 
ra/rb so you can't pass true AS3 ColorTransform into _colorTransform special 
property because it's values will 
not be parsed. You have to manually convert it to custom object with ra/rb 
properties. That's the problem.

Original comment by rolekgrz...@gmail.com on 4 Sep 2007 at 1:53

GoogleCodeExporter commented 8 years ago
rolekgrzegorz: yeah, after the post about the issue (on the discussion list) I
recognized the mistake; it shouldn't be the way it is. It was a bit of a legacy
support but it shouldn't be like that.

The next version will use a proper, native object, similar to buginajar's fix 
but
getting rid of the AS2 syntax/conventions altogether.

Original comment by zisfor...@gmail.com on 4 Sep 2007 at 2:06

GoogleCodeExporter commented 8 years ago
This has been corrected on the new version of Tweener. The old _ra/_rb/etc 
properties
are deprecated and shouldn't be used (even in AS2) anymore.

Thanks.

Original comment by zisfor...@gmail.com on 28 Sep 2007 at 7:22