0

我被一些我确信应该相当简单的事情所困扰。我从库中声明了两条垂直线,然后将每条线依次传递给一个函数,该函数在已传递的线上进行操作。代码执行没有错误,但显然在第二次调用函数时覆盖了第一行,大概是因为在函数头中使用了术语“myLine”。谁能告诉我如何将每一行传递给同一个函数,但该函数只在该行上运行?

代码是:

//declare new lines from library
var myLine1:letterLine = new letterLine();
var myLine2:letterLine = new letterLine();

//call function and pass each line in turn
VerticalLine(myLine1, lineX = stage.stageWidth/2 - lineOffset, lineY, lineLength, lineThickness, lineColour, lineTweenSpeed);
VerticalLine(myLine2, lineX = stage.stageWidth/2 - lineOffset, lineY, lineLength, lineThickness, lineColour, lineTweenSpeed);

//operate on the line passed to the function
function verticalLine(myLine, lineX:int, lineY:int, lineLength:Number, lineThickness:int, lineColour, lineTweenSpeed:Number):void {
    //draw line
    myLine.height = 0;
    myLine.x = lineX;
    myLine.y = lineY;
    myLine.width = lineThickness;

    var myColour:ColorTransform = myLine.transform.colorTransform;
    myColour.color = lineColour;
    myLine.transform.colorTransform = myColour;
    addChild(myLine);

    //set mask properties for line
    var maskW:uint = lineThickness;
    var maskH:uint = lineLength;

    //set gradient properties for mask
    var gradientFillType:String = GradientType.LINEAR;
    var gradientColours:Array = [0x123456, 0x654321, 0x123456, 0x654321];
    var gradientAlphas:Array = [0.4, 1, 1, 0.4];
    var gradientRatios:Array = [0, 100, 155, 255];
    var gradientMatrix:Matrix = new Matrix;

    var maskRotation:Number = Math.PI/2;
    var maskX:int = lineX;
    var maskY:int = myLine.y - lineLength/2;;
    gradientMatrix.createGradientBox(maskW, maskH, maskRotation, maskX, maskY);
    var spreadMethod:String = SpreadMethod.PAD;

    myLine.cacheAsBitmap = true;

    //draw mask shape
    var myMask = new Shape ;
    myMask.graphics.beginGradientFill(gradientFillType, gradientColours, gradientAlphas, gradientRatios, gradientMatrix, spreadMethod);
    myMask.graphics.drawRect(maskX, maskY, maskW, maskH);
    myMask.cacheAsBitmap = true;
    addChild(myMask);

    //mask line
    myLine.mask = myMask;

    TweenLite.to(myLine, lineTweenSpeed,{height:lineLength, ease:Linear.easeIn});
}
4

1 回答 1

0

诀窍是,您为两行发送相同的值,因此它们严格重叠,您将其视为覆盖。当您调用您的函数时,您需要为相应的行提供实际值。像这样:

verticalLine(myLine1, stage.stageWidth/2 - 100, 10, 125, 1, 0xff0000, 0.2);
verticalLine(myLine2, stage.stageWidth/2 - 2, 300, 40, 2, 0x0000ff, 0.3);

还要检查在声明函数和调用它时是否有正确的大小写。

于 2012-11-04T04:41:03.823 回答