Flash AS3:根据当前帧更改变量

时间:2014-05-20 14:23:53

标签: actionscript-3 flash variables actionscript charts

好的,所以我有这个代码创建一个饼图......

package {
import flash.display.Sprite;
import flash.display.MovieClip; 

public class App extends MovieClip {
    function App() {
        this.graphics.lineStyle(3, 0xFF0000);
        this.graphics.beginFill(0xFF0000, 0.5);
        this.drawSegment(this, stage.stageWidth/2, stage.stageHeight/2, piesize, -90, 0);
        this.drawSegment(this, stage.stageWidth/2, stage.stageHeight/2, piesize, 0, 110);
        this.drawSegment(this, stage.stageWidth/2, stage.stageHeight/2, piesize, 110, 180);
        this.drawSegment(this, stage.stageWidth/2, stage.stageHeight/2, piesize, 180, 270);
        this.graphics.endFill();
    }


var piesize:Number = 140;   

    var wedge1:Number = 90;
    var wedge2:Number = 110;
    var wedge3:Number = 90;
    var wedge4:Number = 90;


    /**
     * Draw a segment of a circle
     * @param target    <Sprite> The object we want to draw into
     * @param x         <Number> The x-coordinate of the origin of the segment
     * @param y         <Number> The y-coordinate of the origin of the segment
     * @param r         <Number> The radius of the segment
     * @param aStart    <Number> The starting angle (degrees) of the segment (0 = East)
     * @param aEnd      <Number> The ending angle (degrees) of the segment (0 = East)
     * @param step      <Number=1> The number of degrees between each point on the segment's circumference
     */
    function drawSegment(target:Sprite, x:Number, y:Number, r:Number, aStart:Number, aEnd:Number, step:Number = 1):void {
            // More efficient to work in radians
            var degreesPerRadian:Number = Math.PI / 180;
            aStart *= degreesPerRadian;
            aEnd *= degreesPerRadian;
            step *= degreesPerRadian;

            // Draw the segment
            target.graphics.moveTo(x, y);
            for (var theta:Number = aStart; theta < aEnd; theta += Math.min(step, aEnd - theta)) {
                target.graphics.lineTo(x + r * Math.cos(theta), y + r * Math.sin(theta));
            }
            target.graphics.lineTo(x + r * Math.cos(aEnd), y + r * Math.sin(aEnd));
            target.graphics.lineTo(x, y);
    };
}
}

此代码是根据建议从外部AS文件中提取的。这工作正常,并创建一个可爱的红色饼图与4段。

你会看到变量wedge1,wedge2等当前没有做任何事情,尽管我希望能够在主时间轴的每一帧上更改这些变量。

有没有办法将这些变量放在主时间轴上,当我在这些帧之间移动时,它会改变饼图中的那些变量? (我将只使用左右键一次向前和向后移动一帧)

此外,我将不得不以某种方式更改代码以实现此结果...我已经编写了SUDO样式,但是对此代码的确切执行的任何帮助都将非常感激...

wedge1start == -90
wedge1end == wedge1start + wedge1
wedge2end == wedge1end + wedge2
wedge3end == wedge2end + wedge3
wedge4end == wedge2end + wedge4


this.drawSegment(this, stage.stageWidth/2, stage.stageHeight/2, piesize, wedge1start, wedge1end);
this.drawSegment(this, stage.stageWidth/2, stage.stageHeight/2, piesize, wedge1end, wedge2end);
this.drawSegment(this, stage.stageWidth/2, stage.stageHeight/2, piesize, wedge2end, wedge3end);
this.drawSegment(this, stage.stageWidth/2, stage.stageHeight/2, piesize, wedge3end, wedge4end);

我希望这是有道理的,我基本上试图实现饼图段和大小的变化,因为我向前或向后移动。变量存在,但我似乎无法从AS文件外部更改它们。

我应该使用输入框架还是什么?

感谢您的帮助,对不起那么长的问题

1 个答案:

答案 0 :(得分:0)

假设您发布的课程是您的文档课程,您只需要创建变量public

public var wedge1:Number = 0;

然后在您的主时间轴上,您可以按照伪代码中的名称访问它们。