2 Replies Latest reply on Dec 23, 2012 4:43 AM by supersonicecho

    Problem with Spark DisplacementMapFilter

    jmandawg Level 1

      For some reason, it thinks DisplacementMapFilter is not of type filter.  It doesn't appear i can use this filter on any spark components:


      ArgumentError: Error #2005: Parameter 0 is of the incorrect type. Should be type Filter.
          at flash.display::DisplayObject/set filters()
          at mx.core::UIComponent/set filters()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:3346]
          at DisplacementFilter/cc()[L:\JCCC_Flex_Source\JCCC_Flex\src\DisplacementFilter.mxml:14]
          at DisplacementFilter/___DisplacementFilter_Application1_creationComplete()[L:\JCCC_Flex_Source\JCCC_Flex\src\DisplacementFilter.mxml:4]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.core::UIComponent/dispatchEvent()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:12528]
          at mx.core::UIComponent/set initialized()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:1627]
          at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:759]
          at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]


      Here is the sample code i don't expect it to do anything, but i dont' think it should throw an error:


      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="cc();">
              <!-- Place non-visual elements (e.g., services, value objects) here -->
                  import spark.filters.DisplacementMapFilter;
                  function cc()
                      var tmp:DisplacementMapFilter = new DisplacementMapFilter();
                      lbl.filters = [tmp];
          <s:Label id="lbl" fontSize="16" text="HELLO WORLD"/>

        • 1. Re: Problem with Spark DisplacementMapFilter

          It would be very helpful if someone anwser this post.. i'm playing arround this filter but I cant use it either cause of this error..

          • 2. Re: Problem with Spark DisplacementMapFilter
            supersonicecho Level 2

            Its been awhile since you posted your question, but I just solved the issue and thought it may still be helpful to you and/or others. 


            The way UIComponents use spark filters is to clone them, returning a basic flash version of the filter, and add the basic flash version of the filter to the filters list of the superclass DisplayObject.  Why they do it this way, I am not sure, but this is how it works.


            The reason the spark DisplacementMapFilter doesn't work is because the clone() method does not, well, clone anything.  The fix is extremely simple.  Subclass the filter and override the clone method and return a flash displacement filter.  I suspect this was simply an oversight by the flex devs and since the Displacement filter is so rarely used, no one noticed.


            Here is the code for the spark DisplacementMapFilter that works:


            package customFilters



            import flash.filters.BitmapFilter;

            import flash.filters.DisplacementMapFilter;


            import spark.filters.DisplacementMapFilter;


            public class DisplacementMapFilterFixed extends DisplacementMapFilter



                  override public function clone():BitmapFilter


                                return new flash.filters.DisplacementMapFilter(mapBitmap, mapPoint, componentX, componentY, scaleX, scaleY, mode, color, alpha);