Motion Tween Doesn't Work Inside Function in ActionScript 3 and Flash CS5

1.6k views Asked by At

i have a problem with putting a motion tween in function. my code works perfectly in CS4(but unfortunatly flash CS4 hangs all the time on my PC. whoever in CS5 the motion works fine outside function but when i put it inside a function it behave strangely? i must mention that i'm not a pro in flash and sorry for my poor english.

i have a rectangle shape converted to symbol that i named it s1 here is the code without function:

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

and here when i put motion tween inside function: (i have a rectangle shape converted to symbol that i named it 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);

and now this is work with CS4 and it isn't work in CS5. pleeeeeeease help me

1

There are 1 answers

4
weltraumpirat On BEST ANSWER

__motion_UIL1 and __animFactory_UIL1 are both declared as local variables (inside the function), which essentally means they are erased and forgotten after the function is executed. Try moving

var __motion_UIL1:MotionBase;

and

var __animFactory_UIL1:AnimatorFactory;

out of the function body.