1 Reply Latest reply on Apr 7, 2009 3:54 AM by Seglespaan

    Drop Shadow Filter

    Seglespaan

      Hi,

       

      is it possible to amend the following code so that it renders the drop shadow in real time. i.e. when the button is toggled and the shadow showing, when a user moves one of the sliders the shadow updates in real time??

       

      Cheers

       

      <?xml version="1.0"?>

      <!-- styles/ApplyFilterAS.mxml -->

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

          <mx:Script><![CDATA[

              import flash.filters.*;

       

              public function toggleFilter(distance, angle, color, alpha):void { 

              trace(hSAlpha.value);         

                  if (label1.filters.length == 0) {                       

                      /* The first four properties of the DropShadowFilter constructor are

                         distance, angle, color, and alpha. */

                      var f:DropShadowFilter = new DropShadowFilter(distance,angle,color,alpha);

                      var myFilters:Array = new Array();

                      myFilters.push(f);

                      label1.filters = myFilters;

                  } else {

                      label1.filters = null;

                  }

              }

          ]]></mx:Script>

          <mx:Label id="label1" text="ActionScript-applied filter."/>

          <mx:Button id="b1" label="Toggle Filter" click="toggleFilter(hSdistance.value,hSAngle.value,cpShadowColour.selectedColor,hSAlpha.v alue)"/>

          <mx:HSlider id="hSdistance"

          minimum="0" maximum="20"

          snapInterval="1"

          liveDragging="false"

          enabled="true"

          labels="[0,5,10,15,20]"/>

          <mx:HSlider id="hSAngle"

          labels="[0,90,180,270,360]"

          minimum="0" maximum="360"

          snapInterval="1"

          enabled="true"

          liveDragging="true"/>

          <mx:ColorPicker id="cpShadowColour"/>

          <mx:HSlider id="hSAlpha"

          labels="[0,.25,.5,.75,1]"

          minimum="0" maximum="1"

          snapInterval=".1"

          enabled="true"

          liveDragging="true"

          value="1"/>

      </mx:Application>

        • 1. Re: Drop Shadow Filter
          Seglespaan Level 1

          Answered my Own question, Heres the solution.

           

           

          <?xml version="1.0"?>

          <!-- styles/ApplyFilterAS.mxml -->

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

              <mx:Script><![CDATA[

                  import flash.filters.*;

           

                  public function toggleFilter(distance, angle, color, alpha):void { 

                           

                          /* The first four properties of the DropShadowFilter constructor are

                          distance, angle, color, and alpha. */

                          var f:DropShadowFilter = new DropShadowFilter(distance,angle,color,alpha);

                          var myFilters:Array = new Array();

                          myFilters.push(f);

                          label1.filters = myFilters;

                          b1.selected="true"

                     

                  }

                 

                  public function toggleFilter2():void { 

                          

                      if (label1.filters.length == 0) {                       

                         toggleFilter(hSdistance.value,hSAngle.value,cpShadowColour.selectedColor,hSAlpha.value)

                      } else {

                          label1.filters = null;

                      }

                  }

                 

                 

                 

                 

                 

                 

              ]]></mx:Script>

              <mx:Label id="label1" text="ActionScript-applied filter."/>

              <mx:Button id="b1" label="Toggle Filter" toggle="true" click="toggleFilter2()"/>

              <mx:HSlider id="hSdistance"

              minimum="0" maximum="20"

              snapInterval="1"

              liveDragging="true"

              enabled="true"

              labels="[0,5,10,15,20]"

              change="toggleFilter(hSdistance.value,hSAngle.value,cpShadowColour.selectedColor,hSAlpha.v alue)"/>

              <mx:HSlider id="hSAngle"

              labels="[0,90,180,270,360]"

              minimum="0" maximum="360"

              snapInterval="1"

              enabled="true"

              liveDragging="true"

              change="toggleFilter(hSdistance.value,hSAngle.value,cpShadowColour.selectedColor,hSAlpha.v alue)"/>

              <mx:ColorPicker id="cpShadowColour" change="toggleFilter(hSdistance.value,hSAngle.value,cpShadowColour.selectedColor,hSAlpha. value)"/>

              <mx:HSlider id="hSAlpha"

              labels="[0,.25,.5,.75,1]"

              minimum="0" maximum="1"

              snapInterval=".1"

              enabled="true"

              liveDragging="true"

              value="1"

              change="toggleFilter(hSdistance.value,hSAngle.value,cpShadowColour.selectedColor,hSAlpha.v alue)"/>

          </mx:Application>