ActionScript 3中的.currentFrame [英] .currentFrame in ActionScript 3

查看:188
本文介绍了ActionScript 3中的.currentFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前问过类似的问题,得到了很好的答案,所以我很抱歉,如果这有点令人沮丧。希望这将是一个快速的。我正在设计一个交互式的Flash教程来解释一个复杂的生物学问题,并且我构建了时间轴,以便不超过两个帧和四个层。我之前在Stage时间线上设计过,但是它变得非常混乱,而且有一些问题,我决定我必须这样做。



它由三个主要部分 - 首先在两个部分淡入淡出的标题,然后是两个按钮(在完全淡入之前被禁用)以及最终在循环中无限期地淡入淡出的分子的动画。然后页面保持环境,直到用户单击其中一个按钮。

我在主时间轴上有四个图层 - 动作,按钮,分子和标题。在每一个都是相关的图像和动画。

我想编码,使每个连续播放,但我真的很难通过AS3访问其他时间线



目前我在Actions层有这个:

$ p $ import对象类型:flash.events.Event;

NRPSText_mc.addEventListener(Event.ENTER_FRAME,FadeIn);

函数FadeIn(event:Event):void
{
if(MovieClip(this.root).currentFrame> 0){
NRPSText_mc.gotoAndPlay( NRPSFadeIn)
}
}

ColourButton_mc.addEventListener(Event.ENTER_FRAME,BtnFadeIn);

函数BtnFadeIn(event:Event):void
{
if(NRPSText_mc.currentFrame == 30){
ColourButton_mc.gotoAndPlay(ButtonPress)




$ b $ p
$ b

从这里我可以清楚的看到,在每个时间轴上,我希望他们玩一个完成。

问题是知道在每个实例.currentFrame之前要放什么,我不能在任何地方找到!到目前为止,我已经能够通过使用this和MovieClip(this.root),但我需要能够找到如何引用这些嵌入式时间表,使其工作。我已经试过这些代码与痕迹,它似乎工作正常,所以我认为这是问题的根源所在。 解决方案

首先,如果你在主时间线上有代码而不是 MovieClip(this.root).currentFrame ,你可以使用 currentFrame











$ (MovieClip(this.root).currentFrame> 0){
NRPSText_mc.gotoAndPlay(NRPSFadeIn)
}

只会让NRPSText_mc停留在NRPSFadeIn标签,因为每帧都被调用。 ,如果在舞台上有一个movieclip,并且已经设置了它的实例名称,则可以通过该实例名称引用其时间线FROM父范围(主时间轴),如同使用 NRPSText_mc.gotoAndPlay(NRPSFadeIn)。如果你有一个脚本INSIDE的movieclip只是使用 gotoAndPlay() currentFrame ,因为你在同一个对象作为脚本。



你也有点错了。常用的方法是使用时间轴动画或某种类似的补间库,如 TweenMax 。当你使用Flash IDE时,做同样事情的正确方法如下:用你想要的对象的动画创建单独的动画片段;把它们放在主时间线上,这个时间线有自己的动画,在任何你想要控制内部剪辑的框架上,用 stop() gotoAndPlay()等设置单独的脚本。

如果您想要在剪辑完成时收到通知,请使用AS3事件。例如,你得到了一个名为 mc 的影片剪辑,在最后一帧添加一个脚本 dispatchEvent(new Event(stopped!)); stop(); 和在主时间线上

  mc.addEventListener(stopped!,listener) ; 
函数监听器(event:Event):void {
trace(mc stopped!);





$ b

这样比检查每个输入框事件的帧数要容易得多。 / p>

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.

解决方案

First of all if you have code on main timeline instead of MovieClip(this.root).currentFrame you can just use currentFrame since you are refering to the object you set the script on.

Second, this

if (MovieClip(this.root).currentFrame > 0) {
    NRPSText_mc.gotoAndPlay("NRPSFadeIn")
}

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 use gotoAndPlay() and currentFrame 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 with stop(), 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 frame dispatchEvent(new Event("stopped!")); stop(); and at main timeline

mc.addEventListener("stopped!", listener);
function listener(event:Event):void {
  trace("mc stopped!");
}

This way it is much easier than checking for frame numbers every enterframe event.

这篇关于ActionScript 3中的.currentFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆