Skip to main content
sergiopop75
Inspiring
April 21, 2023
Answered

Apply Adjust Color Filter by jsfl

  • April 21, 2023
  • 1 reply
  • 908 views

To apply a Adjust Color filter I used to use before:

an.getDocumentDOM().addFilter('adjustColorFilter')

But now it doesn't work anymore.

 

 

I found this function that in theory assigns the effect to a layer, but it doesn't work either.

var myFilters = an.getDocumentDOM().getTimeline().layers[0].getFiltersAtFrame(0);

 

The blend modes now work with this code:

an.getDocumentDOM().getTimeline().layers[0].setBlendModeAtFrame(1,"Alpha");

 

 

But I don't know how to apply it to filter effects.

Any help?

    This topic has been closed for replies.
    Correct answer Vladin M. Mitov

    OK, to apply a filter to a frame, you need to use the command setFiltersAtFrame(). If you refer to the documentation, there are described all filter object properties. So, if we want to apply, a new filter, we need to manually construct the filter object and to push it to the filters array. For example:

    var dom = an.getDocumentDOM();
    var tl = dom.getTimeline();
    var layer = tl.layers[ tl.currentLayer ];
    
    var myFilter = {
    	"name": "glowFilter",
    	"enabled": true,
    	"angle": 45,
    	"blurX": 4,
    	"blurY": 4,
    	"distance": 4,
    	"color": "#FF0000",
    	"quality": "low",
    	"inner": false,
    	"knockout": false,
    	"hideObject": false,
    	"strength": 100
    };
    
    
    // In order to keep the filters already applied to the frame,
    // first we get the existing filters array.
    var filters = layer.getFiltersAtFrame( tl.currentFrame ) || [];
    
    // Put the new filter to the array
    filters.push( myFilter );
    
    // And apply modified array back to the frame
    layer.setFiltersAtFrame( tl.currentFrame, filters );
    
    // Set the blend mode
    layer.setBlendModeAtFrame( tl.currentFrame, "Normal" );

     

     

     

    1 reply

    Vladin M. Mitov
    Inspiring
    April 22, 2023

    Hi,

    I just tested the command fl.getDocumentDOM().addFilter("adjustColorFilter")
    and it works as expected - adds a filter to the selected movieclip instances on the stage.


    As for getFiltersAtFrame() and setFiltersAtFrame(),

    they gets and sets the filters on a timeline frame, not to an instance.

    So, where do you want to apply filters?

     

    Edit: Tested in Animate 23.0.1

     

     

    - Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
    sergiopop75
    Inspiring
    April 22, 2023

    Thanks for your reply.

     

    I still can't get the command to work in version 2021 and 2023, in WIN and MAC, I think I saw it working, but now I have doubts.

     

    The idea is to apply it like the BlendMode function, to the top layer [0] and frame 1.

     

    This way it is enabled outside the symbol to see the BlendMode of the Alpha that has the symbol activated.

     

    ____2D vector animator since 2000 & PhD
    Vladin M. Mitov
    Vladin M. MitovCorrect answer
    Inspiring
    April 22, 2023

    OK, to apply a filter to a frame, you need to use the command setFiltersAtFrame(). If you refer to the documentation, there are described all filter object properties. So, if we want to apply, a new filter, we need to manually construct the filter object and to push it to the filters array. For example:

    var dom = an.getDocumentDOM();
    var tl = dom.getTimeline();
    var layer = tl.layers[ tl.currentLayer ];
    
    var myFilter = {
    	"name": "glowFilter",
    	"enabled": true,
    	"angle": 45,
    	"blurX": 4,
    	"blurY": 4,
    	"distance": 4,
    	"color": "#FF0000",
    	"quality": "low",
    	"inner": false,
    	"knockout": false,
    	"hideObject": false,
    	"strength": 100
    };
    
    
    // In order to keep the filters already applied to the frame,
    // first we get the existing filters array.
    var filters = layer.getFiltersAtFrame( tl.currentFrame ) || [];
    
    // Put the new filter to the array
    filters.push( myFilter );
    
    // And apply modified array back to the frame
    layer.setFiltersAtFrame( tl.currentFrame, filters );
    
    // Set the blend mode
    layer.setBlendModeAtFrame( tl.currentFrame, "Normal" );

     

     

     

    - Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation