初学者:在 Haxe/ActionScript3 中动态插入帧到 MovieClip

发布于 2024-07-12 08:41:02 字数 990 浏览 3 评论 0原文

假设我有一个导出 mc1 的资源文件,其中包含 4 个帧。 我想创建一个新的 MovieClip 并插入如下所示的帧:

mc2:flash.display.MovieClip = new flash.display.MovieClip()

mc1.gotoAndStop(2);
mc2.gotoAndStop(1);
mc2.currentFrame = mc1.currenctFrame
mc1.gotoAndStop(1);
mc2.gotoAndStop(2);
mc2.currentFrame = mc1.currenctFrame
mc1.gotoAndStop(2);
mc2.gotoAndStop(3);
mc2.currentFrame = mc1.currenctFrame
mc1.gotoAndStop(4);
mc2.gotoAndStop(4);
mc2.currentFrame = mc1.currenctFrame

[edit] 更多详细信息

我没有使用 Flash IDE。 我正在使用:

  • Inkscape(用于生成 SVG)
  • swfmill(用于创建资源文件)
  • Haxe(用于创建动画)

目前我并没有尝试构建游戏或任何交互式内容。 我成功地创建了一个简单的动画,其中背景精灵正在旋转(仅此而已)。 我使用 TimerEvent 来实现这一点。 但相反,我真的希望能够构建一个 MovieClip 并在其上附加各个帧,然后循环播放。

或者,我可以创建一个 MovieClip,然后以编程方式逐帧绘制。 (然后当然是循环播放)

基本上我想使用 ActionScript 来生成内容而不是 swfmill 的 XML(不是 simple 方言,simple 就可以了)。 由于我是初学者,我不知道我还能给你什么其他信息。 那么请告诉我是否可以提供任何其他详细信息?

Let's say I have a resource file which exports mc1 with 4 frames in it. I would like to create a new MovieClip and insert frames like this:

mc2:flash.display.MovieClip = new flash.display.MovieClip()

mc1.gotoAndStop(2);
mc2.gotoAndStop(1);
mc2.currentFrame = mc1.currenctFrame
mc1.gotoAndStop(1);
mc2.gotoAndStop(2);
mc2.currentFrame = mc1.currenctFrame
mc1.gotoAndStop(2);
mc2.gotoAndStop(3);
mc2.currentFrame = mc1.currenctFrame
mc1.gotoAndStop(4);
mc2.gotoAndStop(4);
mc2.currentFrame = mc1.currenctFrame

[edit] More details

I am not using Flash IDE. I am using:

  • Inkscape (for SVG generation)
  • swfmill (to create asset files)
  • Haxe (to create animations)

I am not at this point trying to build games or anything interactive. I have managed to create a simple animation where a background sprite is spinning (and that's it). I used TimerEvents to achieve this. But instead I would really like to be able to construct a MovieClip and attach individual frames on it and then play it on loop.

Alternatively I can create a MovieClip and just draw on it frame by frame programmatically. (and then of course play in loop)

Basically I would like to use ActionScript to generate content instead of swfmill's XML (not the simple dialect, simple is fine). Since I am a beginner I don't know what other information I can give you. So please tell me if I can supply any other details?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丑疤怪 2024-07-19 08:41:03

如果没有 Flash IDE,使用 gotoAndStop() 等就没有什么意义。

由于您无法在不同的帧上添加不同的资源,因此您应该使用 addChild(assetToAdd) 将它们全部添加为图层,并将除一个之外的所有资源设置为visible = false 。 然后添加一个简单的函数,如下所示:

function showFrame(num:int):void
{
    for (var i:int = 0; i < numChildren; i++)
    {
       if (i == num)
       {
          getChildAt(i).visible = true;
       }
       else
       {
          getChildAt(i).visible = false;
       }
    }
}

Without the Flash IDE, there is little point in using gotoAndStop() etc.

As you can't add your different assets on different frames, you should add them all as layers using addChild(assetToAdd) and set all but one to visible = false. Then add a simple function like this:

function showFrame(num:int):void
{
    for (var i:int = 0; i < numChildren; i++)
    {
       if (i == num)
       {
          getChildAt(i).visible = true;
       }
       else
       {
          getChildAt(i).visible = false;
       }
    }
}
葬花如无物 2024-07-19 08:41:03

我不知道有什么方便的方法可以完成您想要做的事情。 您的示例将不起作用,因为 currentFrame 是只读属性,而且它返回的只是表示帧编号的整数,而不是构成实际帧的数据。

我的建议是,如果您需要动态重新排列帧,请将特定的 MovieClip 包装在自定义类中,该类将 gotoAndPlay(x) 转换为您想要的任何数字。

然而,这可能不是很有用,具体取决于您想要实现的目标,但如果您稍微澄清一下您的问题,我相信我们可以提出正确的建议。

I'm not aware of a convenient way to do what you're trying to do. Your example won't work because currentFrame is a read-only property, also all it returns is an integer representing the frame number, not the data making up the actual frame.

My suggestion, if you need to dynamically rearrange the frames, would be to wrap that particular MovieClip in a custom class that translates the gotoAndPlay(x) to whatever number you would want.

However, this might not be very useful depending on what you're trying to achieve, but if you clarify your question a bit I'm sure we can come up with a proper suggestion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文