我堅持的東西,我相信應該相當簡單。我從庫中聲明瞭兩條垂直線,然後依次將每條線傳遞給一個函數,該函數在它傳遞的線上運行。代碼執行時沒有錯誤,但顯然當函數被第二次調用時覆蓋第一行,大概是因爲在函數頭中使用了「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});
}
發佈函數體。我強烈懷疑你的想法正在發生什麼。 –
我沒有看到任何代碼,會導致你在說什麼。想法:你兩次都傳遞相同的值,所以兩行都是相同的(或者只是爲了說明在帖子中調用了兩次) –
Hello Jason。不,不僅僅是一個插圖 - 我需要兩次調用該函數,並讓它在兩個單獨的myline對象上運行。對我自己的想法:如果函數被調用時它是否在當前正在早期調用中運行?*換句話說,Flash是否停止執行(並放棄)第一次調用並重新開始,或者開始執行從某種意義上講,可以創建與該函數調用一樣多的函數,以獨立執行函數調用。那有意義嗎?! –