How can I get the alpha value on an Instance (in JSFL)?

大憨熊 提交于 2019-12-13 06:44:56

问题


If I use simple Alpha color effects on an instance on the stage, how do I access it via JSFL?

An instance's *.colorAlphaAmount and *.colorAlphaPercent doesn't access the above illustration's value. It's only useful for "Advanced Color" effects.

It looks like fl.getDocumentDOM().setInstanceAlpha(18); can SET the alpha property, but NOT GET it. Also, this method would assume that the instance is selected in the current timeline / layer / frame, which I likely wouldn't (since I'm iterating through the library without opening each individual symbols).

Is there an alpha value hidden away in the instances somewhere else?


回答1:


Actually, I'm dumb! colorAlphaPercent is the correct value to read it from.

HOWEVER, if the alpha is tweened, it won't be read correctly. It will only refer to the alpha value at the keyframes of the animation, not in between it.

So for simple linear, easeIn and easeOut tweens, I've developed this MathUtils class that may be of help to others who are trying to read alpha AND other values (x,y,scale,skew,rotation) from a tween animation.

You can put the following in it's own JSFL file, and load it wherever you need it.

MathUtils = {
    pi2: Math.PI/2,
    easeValue: function( pStart, pFinish, pRatio, pEasing ) {
        var diff = pFinish - pStart;

        var eased =     pEasing > 0 ? this.easeOut( pRatio ) : this.easeIn( pRatio );
        var linear =    pRatio;

        var blendRatio =    Math.abs(pEasing);
        var easeBlend =     blendRatio * eased;
        var linearBlend =   (1 - blendRatio) * linear;

        return pStart + diff * (easeBlend + linearBlend);
    },
    easeIn: function( pRatio ) {
        return 1 - Math.sin((1-pRatio) * this.pi2);
    },
    easeOut: function( pRatio ) {
        return Math.sin(pRatio * this.pi2);
    }
};

How to use this:

pStart, pFinish: Provide the start value and end value of the element you are trying to read from (in other words, it's alpha from the start keyframe and the next one).

pRatio: A value from 0.0 to 1.0 indicating how far into the tween the given frame is. Usually, this value can be calculated with (currentFrameID - startFrameID) / (endFrameID - startFrameID).

pEasing: The easing value given for the startFrame, usually between -100 and 100 (0 = linear).




回答2:


Nice class!

Does it work the same as converting to keyframes and reading the values?

If so, that's a really good idea (hopefully we won't need this in CS7!)



来源:https://stackoverflow.com/questions/14280834/how-can-i-get-the-alpha-value-on-an-instance-in-jsfl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!