我怎样才能得到一个实例(在JSFL)的alpha值? [英] How can I get the alpha value on an Instance (in JSFL)?

查看:325
本文介绍了我怎样才能得到一个实例(在JSFL)的alpha值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在舞台上的一个实例上使用简单的Alpha颜色效果,我如何通过JSFL访问它?


实例的* .colorAlphaAmount和* .colorAlphaPercent不能访问上面的插图的价值。它只是用于高级颜色效果。



它看起来像 fl.getDocumentDOM()。setInstanceAlpha(18); 可以设置alpha财产,但不是获取它。另外,这个方法会假定在当前的时间轴/图层/框架中选择实例,我可能不会这样做(因为我在不打开每个符号的情况下遍历库)。

是否有一个alpha值被隐藏在其他地方的实例中?

解决方案

其实,我哑! colorAlphaPercent 是读取它的正确值。

然而,如果alpha被补间,它将不会被正确读取。它只会引用动画的关键帧的alpha值,而不是介于它之间。



因此,对于简单的线性,easeIn和easeOut补间,我已经开发了这个MathUtils类,它可以帮助其他尝试从补间动画中读取alpha和其他值(x,y,比例,倾斜,旋转)的其他人。

您可以将以下内容放在它自己的JSFL文件中,并在需要时加载它。

  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);
}
};

如何使用这个:

pStart,pFinish :提供您尝试读取的元素的起始值和结束值(换句话说,它是从开始关键帧到下一个元素的字母)。



:从0.0到1.0的值,指示给定帧的补间距离。通常,可以使用(currentFrameID - startFrameID)/(endFrameID - startFrameID)来计算此值。

pEasing :为 startFrame 提供的宽松值,通常在-100和100之间(0 =线性)。


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?

解决方案

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

这篇关于我怎样才能得到一个实例(在JSFL)的alpha值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆