سؤال

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

enter image description here

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?

هل كانت مفيدة؟

المحلول

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).

نصائح أخرى

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!)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top