ActionScript 3 中的 .currentFrame
我之前问过类似的问题并得到了很好的答案,所以如果这有点令人沮丧,我深表歉意。希望这会很快。我正在设计一个交互式 Flash 教程,试图解释一个复杂的生物学问题,并且我已经构建了时间轴,使其不超过两帧和四层。我之前在舞台时间轴上设计过这个,但它变得非常混乱,并且出现了一些问题,所以我决定必须以这种方式重做。
它由三个主要部分组成 - 首先分两段淡入的标题,然后是两个按钮(在完全淡入之前禁用),最后是在循环中无限期淡入和淡出的分子动画。然后,该页面将保持环境状态,直到用户单击其中一个按钮。
我的主时间线上有四层 - 动作、按钮、分子和标题。每个都有相关的图像和动画。
我想对其进行编码,以便每个时间线依次播放,但我很难通过 AS3 访问其他时间线。
目前我在“动作”层中有这个:
import flash.events.Event;
NRPSText_mc.addEventListener(Event.ENTER_FRAME, FadeIn);
function FadeIn(event:Event):void
{
if (MovieClip(this.root).currentFrame > 0) {
NRPSText_mc.gotoAndPlay("NRPSFadeIn")
}
}
ColourButton_mc.addEventListener(Event.ENTER_FRAME, BtnFadeIn);
function BtnFadeIn(event:Event):void
{
if (NRPSText_mc.currentFrame == 30) {
ColourButton_mc.gotoAndPlay("ButtonPress")
}
}
从中可以清楚地看出,我已经在每个时间轴中标记了某些事件,并且我希望它们在完成时播放。
问题是知道在每个实例中在“.currentFrame”之前放置什么,但我在任何地方都找不到它!到目前为止,我已经能够使用“this”和“MovieClip(this.root)”,但我需要能够找出如何引用这些嵌入的时间线以使其工作。我已经用“trace”尝试过这些代码,它似乎工作正常,所以我认为这就是问题所在。
I asked before with a similar problem and received a great answer, so I apologise if this is a little frustrating. Hopefully it will be a quick one. I'm designing an interactive Flash tutorial in an effort to explain a complex biological problem, and I have structured the Timeline so that there are no more than two frames and four layers. I designed this before on the Stage timeline but it became so messy, and with a few problems, that I decided I had to redo it this way.
It consist of three main parts - A title that fades in first in two segments, followed by two buttons (that are disabled until they fully fade in) and finally animations of molecules that fade in and out indefinitely on a loop. The page then stays ambient until a user clicks one of the buttons.
I have four layers on the main timeline - Actions, Buttons, Molecules and Titles. In each are the relevant images and animations.
I want to code it so that each plays successively after the other, but I'm having real difficult accessing other timelines through AS3.
Currently I have this in the Actions layer:
import flash.events.Event;
NRPSText_mc.addEventListener(Event.ENTER_FRAME, FadeIn);
function FadeIn(event:Event):void
{
if (MovieClip(this.root).currentFrame > 0) {
NRPSText_mc.gotoAndPlay("NRPSFadeIn")
}
}
ColourButton_mc.addEventListener(Event.ENTER_FRAME, BtnFadeIn);
function BtnFadeIn(event:Event):void
{
if (NRPSText_mc.currentFrame == 30) {
ColourButton_mc.gotoAndPlay("ButtonPress")
}
}
It should be clear from this that I've labelled certain events in each timeline, and I want them to play as one finishes.
The problem is knowing what to put before ".currentFrame" in each instance, and I can't find it anywhere! Until now I have been able to get by using "this" and "MovieClip(this.root)", but I need to be able to find out how to references these embedded timelines to make it work. I've tried these codes with "trace" and it seems to work fine, so I assume this is where the problem lies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果您在主时间轴上有代码而不是
MovieClip(this.root).currentFrame
,您可以只使用currentFrame
因为您引用的是您设置脚本的对象在。其次,这只
会使 NRPSText_mc 自调用每个帧以来一直保持在“NRPSFadeIn”标签。
第三,如果舞台上有一个影片剪辑并且已设置其实例名称,则可以通过该实例名称从父范围(主时间线)引用其时间线,就像使用
NRPSText_mc.gotoAndPlay("NRPSFadeIn")
。如果您在该影片剪辑内有一个脚本,只需使用gotoAndPlay()
和currentFrame
因为您与脚本位于同一对象中。而且你做的有点不对。常见的方法是使用时间轴动画或某种补间库,例如 TweenMax。当您使用 Flash IDE 时,执行相同操作的正确方法如下:使用您想要的对象的任何动画创建单独的影片剪辑;将它们放在主时间轴上,该时间轴有自己的涉及这些剪辑的动画;在您想要控制内部剪辑的任何帧上,使用
stop()
、gotoAndPlay()
等设置单独的脚本。如果您想在剪辑完成播放时收到通知,请使用AS3 事件。例如,您有一个名为
mc
的影片剪辑,将脚本添加到最后一帧dispatchEvent(new Event("stopped!")); stop();
并在主时间轴上这种方式比检查每个 Enterframe 事件的帧号要容易得多。
First of all if you have code on main timeline instead of
MovieClip(this.root).currentFrame
you can just usecurrentFrame
since you are refering to the object you set the script on.Second, this
will just make NRPSText_mc stay at "NRPSFadeIn" label since called each frame.
Third, if you have a movieclip on stage and you have set its instance name you can reference its timeline FROM parent scope (main timeline) by that instance name as you do with
NRPSText_mc.gotoAndPlay("NRPSFadeIn")
. If you got a script INSIDE that movieclip just usegotoAndPlay()
andcurrentFrame
because you are in the same object as a script.Also you are doing it a bit wrong. Common approach is to use timeline animation or some kind of a tweening library like
TweenMax
. As you are using Flash IDE the proper way of doing same thing would be the following: create separate movieclips with whatever animation for your objects you want; place them on main timeline which got its own animation involving these clips; on whatever frame you want to control your inner clips set separate scripts withstop()
,gotoAndPlay()
, etc.If you want to be notified when a clip finished playing use AS3 events. For example you got a movieclip named
mc
, add a script to the last framedispatchEvent(new Event("stopped!")); stop();
and at main timelineThis way it is much easier than checking for frame numbers every enterframe event.