【问题标题】:Motion Tween Doesn't Work Inside Function in ActionScript 3 and Flash CS5补间动画在 ActionScript 3 和 Flash CS5 中的函数内部不起作用
【发布时间】:2011-06-25 12:54:41
【问题描述】:

我无法在函数中添加补间动画。我的代码在 CS4 中完美运行(但不幸的是,闪存 CS4 一直挂在我的 PC 上。无论谁在 CS5 中,动作在函数外都可以正常工作,但是当我把它放在函数中时,它的行为很奇怪?我必须提到我不是专业人士闪现并为我糟糕的英语感到抱歉。

我有一个矩形形状转换为符号,我将它命名为 s1 这是没有功能的代码:

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import flash.filters.*;
import flash.geom.Point;
import fl.motion.Motion;
import flash.display.DisplayObject;

var __motion_UIL1:MotionBase;
if(__motion_UIL1 == null) 
{
    import fl.motion.Motion;
    __motion_UIL1 = new Motion();
    __motion_UIL1.duration = 15;
    //__motion_UIL1.overrideTargetTransform();

    __motion_UIL1.addPropertyArray("x", [-280,-260,-240,-220,-200,-180,-160,-140,-120,-100,-80,-60,-40,-20,0]);
    __motion_UIL1.addPropertyArray("y", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);

    __motion_UIL1.addPropertyArray("scaleX", [1.000000]);
    __motion_UIL1.addPropertyArray("scaleY", [1.000000]);
    __motion_UIL1.addPropertyArray("skewX", [0]);
    __motion_UIL1.addPropertyArray("skewY", [0]);
    __motion_UIL1.addPropertyArray("rotationConcat", [0]);
    __motion_UIL1.addPropertyArray("blendMode", ["normal"]);
    __motion_UIL1.initFilters(["flash.filters.BlurFilter"], [0], -1, -1);

    __motion_UIL1.addFilterPropertyArray(0, "blurX", [200,185.714,171.429,157.143,142.857,128.571,114.286,100,85.7143,71.4286,57.1429,42.8572,28.5715,14.2857,0], -1, -1);
    __motion_UIL1.addFilterPropertyArray(0, "blurY", [0], -1, -1);  

    __motion_UIL1.addFilterPropertyArray(0, "quality", [BitmapFilterQuality.LOW], -1, -1);

    var __animFactory_UIL1:AnimatorFactory = new AnimatorFactory(__motion_UIL1);
    __animFactory_UIL1.transformationPoint = new Point(0.500000, 0.500000);

    __animFactory_UIL1.addTarget(s1, 1);
}

当我将补间动画放入函数中时: (我有一个矩形形状转换为我命名为 s1 的符号)

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import flash.filters.*;
import flash.geom.Point;
import fl.motion.Motion;
import flash.display.DisplayObject;

function b1(UILx:DisplayObject)
{
    var __motion_UIL1:MotionBase;
    if(__motion_UIL1 == null) 
    {
        import fl.motion.Motion;
        __motion_UIL1 = new Motion();
        __motion_UIL1.duration = 15;
        //__motion_UIL1.overrideTargetTransform();

        __motion_UIL1.addPropertyArray("x", [-280,-260,-240,-220,-200,-180,-160,-140,-120,-100,-80,-60,-40,-20,0]);
        __motion_UIL1.addPropertyArray("y", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);

        __motion_UIL1.addPropertyArray("scaleX", [1.000000]);
        __motion_UIL1.addPropertyArray("scaleY", [1.000000]);
        __motion_UIL1.addPropertyArray("skewX", [0]);
        __motion_UIL1.addPropertyArray("skewY", [0]);
        __motion_UIL1.addPropertyArray("rotationConcat", [0]);
        __motion_UIL1.addPropertyArray("blendMode", ["normal"]);
        __motion_UIL1.initFilters(["flash.filters.BlurFilter"], [0], -1, -1);

        __motion_UIL1.addFilterPropertyArray(0, "blurX", [200,185.714,171.429,157.143,142.857,128.571,114.286,100,85.7143,71.4286,57.1429,42.8572,28.5715,14.2857,0], -1, -1);
        __motion_UIL1.addFilterPropertyArray(0, "blurY", [0], -1, -1);  

        __motion_UIL1.addFilterPropertyArray(0, "quality", [BitmapFilterQuality.LOW], -1, -1);

        var __animFactory_UIL1:AnimatorFactory = new AnimatorFactory(__motion_UIL1);
        __animFactory_UIL1.transformationPoint = new Point(0.500000, 0.500000);

        __animFactory_UIL1.addTarget(UILx, 1);
    }
}

b1(s1);

现在这适用于 CS4,但不适用于 CS5。 请帮帮我

【问题讨论】:

  • 除了看起来像小火车残骸的代码之外,这似乎可以编译并作为时间线脚本正常工作。你能更具体地解决这个问题吗?你有错误吗?
  • 没有。完全没有错误。但是第一个代码模糊并将我的 s1 符号在屏幕上移动 15 帧,第二个代码在不移动 1 帧的情况下进行模糊(没有模糊或移动动画)。

标签: flash actionscript-3 flash-cs4 flash-cs5


【解决方案1】:

__motion_UIL1 和 __animFactory_UIL1 都被声明为局部变量(在函数内部),这实质上意味着它们在函数执行后被擦除和遗忘。尝试移动

var __motion_UIL1:MotionBase;

var __animFactory_UIL1:AnimatorFactory;

在函数体之外。

【讨论】:

  • 另外,我同意@grapefrukt 的观点:代码确实看起来像一场小火车;)
  • 谢谢。这很有帮助。我测试你的建议,你是对的。但是在flash cs4中我没有这个问题。如果我使用你的方式,那么我将无法在运行时动态使用此函数与任何其他影片剪辑或显示对象?你有什么建议吗?
  • 它也不应该在 CS4 中工作 ;) id 确实可能与不同的垃圾收集机制有关,但这充其量只是巧合。您仍然可以动态使用该函数,但您必须围绕它构建一个类(并为每个要移动的显示对象使用“新”实例化它)或为每个动作使用一个 MotionBase 和一个 AnimatorFactory,将两者作为参数与显示对象一起传递给函数。
  • 非常感谢。你提到的第二种方式对我来说会更容易。你很有帮助。再次感谢
猜你喜欢
  • 2011-04-29
  • 2011-06-21
  • 1970-01-01
  • 2012-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-07
  • 1970-01-01
相关资源
最近更新 更多