【问题标题】:Flash AS3: Change variables depending on current frameFlash AS3:根据当前帧更改变量
【发布时间】:2014-07-08 20:56:19
【问题描述】:

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

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 文件外部更改它们。

我应该使用 on enter 框架还是什么??

感谢您的帮助,抱歉问题太长了

【问题讨论】:

    标签: actionscript-3 flash variables actionscript charts


    【解决方案1】:

    假设你发布的类是你的文档类,你需要做的就是让你的变量public:

    public var wedge1:Number = 0;
    

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

    【讨论】:

    • 谢谢。我现在实际上已经在动画的第 2 帧和第 4 帧上改变了变量。然而,我一直缺少的是在输入框架上创建的馅饼。我尝试在“功能应用程序”周围添加 ENTER_FRAME 侦听器,但每次我收到错误,因为某些东西或其他东西未定义。我知道没有定义阶段,但不明白如何定义它或定义一些东西来放置这个动作!我卡住了
    • 在将内容添加到显示列表时会自动定义阶段。您可以使用Event.ADDED_TO_STAGE 事件收听它。如果您仍有问题,我明天可以为您提供更多帮助。
    • 好的,所以我现在每帧都绘制了饼图,所以“piesize”会影响它的大小。我没有意识到精灵不会消失,所以我有数百个饼图彼此叠加,这会产生一些奇怪的结果......现在我只需要弄清楚如何在重新加载之前删除那个饼图,我在我去那里的路上......如果你明天能帮助我,那就太棒了,我没有问题支付你的时间。我现在给你发消息。谢谢
    • 看来我不能给你发消息,如果你能把你的联系方式发给我 gogeye dot com 的 pete,我将不胜感激。谢谢
    • 无需直接发送消息或付款。您是在同一个精灵上绘制饼图,还是每次都在新的精灵上绘制?您能否更新您的问题以包含您用于创建新饼图的代码 - 在您的伪代码中将其绘制到您的文档类中。
    猜你喜欢
    • 2020-01-28
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    相关资源
    最近更新 更多