Passing effect as parameter to a function

Hi all,

I’m trying to generalize a method so that I can apply a predefined filter across multiple display objects.

Based on applying an effect like this:

displayObject.fill.effect = "filter.colorPolynomial" displayObject.fill.effect.coefficients = { 0, 0, 1, 0, --red coefficients 0, 0, 1, 0, --green coefficients 0, 1, 0, 0, --blue coefficients 0, 0, 0, 1 --alpha coefficients }

I tried the following:

--Applies the given effect to the view and overviews displayViewImageFilter = function (thisEffect) --Apply to back image viewBackImage.fill.effect = thisEffect --Apply to all overviews for i, overviewImage in pairs(overviews) do overviewImage.fill.effect = thisEffect end end

But I can’t figure out how to build the thisEffect parameter so that it can be passed into the method.  Trying code below will return “Attempt to index thisEffect (a string value)”:

local thisEffect = "filter.colorPolynomial" thisEffect.coefficients = { 0, 0, 1, 0, --red coefficients 0, 0, 1, 0, --green coefficients 0, 1, 0, 0, --blue coefficients 0, 0, 0, 1 --alpha coefficients } displayViewImageFilter(thisEffect)

I assume there’s something going on behind the scenes when you set displayObject.fill.effect to a String.  Is what I’m trying to do even possible?

Cheers.

Yeah, you can’t do that.

You’ll need to pass the effect name and parameters as two separate arguments and then apply them to your object.
 
This isn’t really assigning a string to effect: 

displayObject.fill.effect = "filter.colorPolynomial"

I’m pretty sure this is actually doing more behind the scenes and the results is that fill is a special object afterwards.

You can confirm this on your own by doing this:

print(displayObject.fill.effect )

Maybe do this instead:

displayViewImageFilter = function (details) --Apply to back image viewBackImage.fill.effect = details.name --Apply to all overviews for k,v in pairs( details.params ) do viewBackImage.fill.effect[k] = v end end

Then do this:
 

local thisEffect = { name = "filter.colorPolynomial", params = { coefficients = { 0, 0, 1, 0, --red coefficients 0, 0, 1, 0, --green coefficients 0, 1, 0, 0, --blue coefficients 0, 0, 0, 1 --alpha coefficients }, } displayViewImageFilter(thisEffect)

Worked like a charm!  Thanks, RG!!

Yeah, you can’t do that.

You’ll need to pass the effect name and parameters as two separate arguments and then apply them to your object.
 
This isn’t really assigning a string to effect: 

displayObject.fill.effect = "filter.colorPolynomial"

I’m pretty sure this is actually doing more behind the scenes and the results is that fill is a special object afterwards.

You can confirm this on your own by doing this:

print(displayObject.fill.effect )

Maybe do this instead:

displayViewImageFilter = function (details) --Apply to back image viewBackImage.fill.effect = details.name --Apply to all overviews for k,v in pairs( details.params ) do viewBackImage.fill.effect[k] = v end end

Then do this:
 

local thisEffect = { name = "filter.colorPolynomial", params = { coefficients = { 0, 0, 1, 0, --red coefficients 0, 0, 1, 0, --green coefficients 0, 1, 0, 0, --blue coefficients 0, 0, 0, 1 --alpha coefficients }, } displayViewImageFilter(thisEffect)

Worked like a charm!  Thanks, RG!!