0

这是我使用的代码。我正在尝试动态创建多个形状并使用它们创建动画(函数 drawLine)。我的结果只显示了一个动画(第一个),然后什么也没有。应该是6个动画。我认为 addChild() 函数并没有像我想要的那样创建多个形状。

  import flash.display.Shape;

var startPoint:Point = new Point();
var endPoint:Point = new Point();

var prog:Number = 0;
var bonus:Number = 1;
var frames:int = 150;

var numbers:Array = new Array();

numbers[0] = new Array();
numbers[0][0] = 460;
numbers[0][1] = 100;

numbers[1] = new Array();
numbers[1][0] = 10;
numbers[1][1] = 20;

numbers[2] = new Array();
numbers[2][0] = 10;
numbers[2][1] = 100;

numbers[3] = new Array();
numbers[3][0] = 10;
numbers[3][1] = 180;

numbers[4] = new Array();
numbers[4][0] = 160;
numbers[4][1] = 20;

numbers[5] = new Array();
numbers[5][0] = 160;
numbers[5][1] = 100;

numbers[6] = new Array();
numbers[6][0] = 160;
numbers[6][1] = 180;

numbers[7] = new Array();
numbers[7][0] = 310;
numbers[7][1] = 20;

numbers[8] = new Array();
numbers[8][0] = 310;
numbers[8][1] = 100;

numbers[9] = new Array();
numbers[9][0] = 310;
numbers[9][1] = 180;

var fullDate:String = "271524";

var i:Number;
var pom:Number;
var shapes:Vector.<Shape> = new Vector.<Shape>();
for (i=0; i < fullDate.length; i++){

    pom = int(fullDate.charAt(i));
    shapes[i] = new Shape();
    addChild(shapes[i]);

    trace(numbers[pom+1][0]);
    drawLine(numbers[pom][0], numbers[pom][1], numbers[pom+1][0], numbers[pom+1][1], 120);
}

function drawLine(startX:Number, startY:Number, endX:Number, endY:Number, time:Number = 120):void {
    startPoint.x = startX;
    startPoint.y = startY;
    endPoint.x = endX;
    endPoint.y = endY;

    frames = time;
    prog = 0;
    this.addEventListener(Event.ENTER_FRAME, tick);
}

function drawLineTick(progress:Number):void{
    for each(var shape:Shape in shapes)
    {
        shape.graphics.clear();
        shape.graphics.lineStyle(14,0x2dfdfd);

        shape.graphics.moveTo(startPoint.x,startPoint.y);
        shape.graphics.lineTo(startPoint.x + ((endPoint.x - startPoint.x) * progress), startPoint.y + ((endPoint.y - startPoint.y) * progress));

    }

}

function tick(e:Event):void {
    if(prog >= frames){
        this.removeEventListener(Event.ENTER_FRAME, tick);
    }

    drawLineTick(prog / frames);    
    prog += bonus;
} 
4

1 回答 1

0

问题是,s仅指Shape您创建的最后一个。尝试这样的事情:(目前,所有形状都在每个形状的顶部,所以你不会看到多个动画,但你可以调整它)

fullDate = "174689";
var shapes:Vector.<Shape> = new Vector.<Shape>();
for (i=0; i < fullDate.length; i++){
    pom = int(fullDate.charAt(i));

    shapes[i] = new Shape();
    addChild(shapes[i]);
    drawLine(numbers[pom][0], numbers[pom][1], numbers[pom+1][0], numbers[pom+1][1], 50);
}


function drawLine(startX:Number, startY:Number, endX:Number, endY:Number, time:Number = 120):void {
    startPoint.x = startX;
    startPoint.y = startY;
    endPoint.x = endX;
    endPoint.y = endY;

    frames = time;
    prog = 0;
    this.addEventListener(Event.ENTER_FRAME, tick);
}

function drawLineTick(progress:Number):void{
    for each(var shape:Shape in shapes)
    {
        shape.graphics.clear();
        shape.graphics.lineStyle(14,0x2dfdfd);

        shape.graphics.moveTo(startPoint.x,startPoint.y);
        shape.graphics.lineTo(startPoint.x + ((endPoint.x - startPoint.x) * progress), startPoint.y + ((endPoint.y - startPoint.y) * progress));

    }

}

function tick(e:Event):void {
    if(prog >= frames){
        this.removeEventListener(Event.ENTER_FRAME, tick);
    }

    drawLineTick(prog / frames);    
    prog += bonus;
} 
于 2012-06-30T16:58:12.453 回答