Search code examples
actionscript-3flashapache-flexactionscript

Button is not functioning properly (Resetting AdjustColors)


I'm using AdjustColor\ColorMatrixFilter to change the Color (Brightness, Contrast, Hue, Saturation) of an Element (remoteVideo), which is controlled using Sliders.

My issue is when the button with the label RESET COLORS is clicked the four sliders

BrightnessSlider.value = 0; 
ContrastSlider.value = 0; 
HueSlider.value = 0; 
SaturationSlider.value = 0; 

do move back to their default position of 0, but only the Contrast and Saturation is reset. I've also tried removing the call to the function adjustColor() and repeating the same steps contained within that function without success.

Update: I also tried filter.matrix = null; remoteVideo.filters = null; but the same issue still stands.

Libraries:

import flash.display.Sprite;
import fl.motion.AdjustColor;
import flash.filters.ColorMatrixFilter;
import fl.events.SliderEvent;   
import flash.external.ExternalInterface;

Variables:

// color change
private var color:AdjustColor = new AdjustColor(); //This object will hold the color properties
private var filter:ColorMatrixFilter = new ColorMatrixFilter(); //Will store the modified color filter to change the video

Function:

private function resetColors(e:Event = null):void
{

    // reset all sliders to 0
    BrightnessSlider.value = 0; 
    ContrastSlider.value = 0; 
    HueSlider.value = 0; 
    SaturationSlider.value = 0; 

    adjustColor();

}

private function adjustColor(e:Event = null):void 
{ 
    color.brightness = BrightnessSlider.value; 
    color.contrast = ContrastSlider.value; 
    color.hue = HueSlider.value; 
    color.saturation = SaturationSlider.value; 
    filter.matrix = color.CalculateFinalFlatArray(); 
    remoteVideo.filters = [filter];     
} 

GUI:

<s:NavigatorContent label="ADJUST COLORS" enabled="{currentState != LoginNotConnected}">
    <s:layout>
        <s:HorizontalLayout/>
    </s:layout>

    <s:VGroup>
        <s:HGroup>
            <s:Panel width="247" height="67.5" backgroundColor="0xA0A0A0"
                             title="Brightness">
                <s:layout>
                    <s:VerticalLayout paddingLeft="8"/>
                </s:layout>
                <s:HSlider id="BrightnessSlider" width="220" change="adjustColor(event)" maximum="100" minimum="-100" showDataTip="false" value="0"/>
            </s:Panel>

            <s:Panel width="247" height="67.5" backgroundColor="0xA0A0A0"
                             title="Contrast">
                <s:layout>
                    <s:VerticalLayout paddingLeft="8"/>
                </s:layout>
                <s:HSlider id="ContrastSlider" width="220" change="adjustColor(event)"
                                   maximum="100" minimum="-100" showDataTip="false" value="0"/>
            </s:Panel>
        </s:HGroup>

        <s:HGroup>
            <s:Panel width="247" height="67.5" backgroundColor="0xA0A0A0" title="Hue">
                <s:layout>
                    <s:VerticalLayout paddingLeft="8"/>
                </s:layout>
                <s:HSlider id="HueSlider" width="220" change="adjustColor(event)" maximum="180" minimum="-180" showDataTip="false" value="0"/>
            </s:Panel>
            <s:Panel width="247" height="67.5" backgroundColor="0xA0A0A0"
                             title="Saturation">
                <s:layout>
                    <s:VerticalLayout paddingLeft="8"/>
                </s:layout>
                <s:HSlider id="SaturationSlider" width="220"
                                   change="adjustColor(event)" maximum="100" minimum="-100" showDataTip="false" value="0"/>
            </s:Panel>

        </s:HGroup>

        <s:Button label="RESET COLORS" click="resetColors(event)" styleName="buttonStyle"/>
    </s:VGroup>

</s:NavigatorContent>

Solution

  • In your resetColors function you don't need the call to adjustColor. Remove it and replace it with remoteVideo.filters = null;

        private function resetColors(e:Event = null):void
        {
            // reset all sliders to 0
            BrightnessSlider.value = 0; 
            ContrastSlider.value = 0; 
            HueSlider.value = 0; 
            SaturationSlider.value = 0;
            remoteVideo.filters = null;
        }