.currentFrame in ActionScript 3

I asked a question with a similar problem and got a great answer, so I apologize if this is a little frustrating. Hope it will be fast. I am developing an interactive Flash tutorial to explain a complex biological problem, and I structured the timeline so that there are no more than two frames and four layers. I designed it earlier on stage, but it got so confusing, and with a few problems, I decided that I had to redo it that way.

It consists of three main parts: the name, which disappears first in two segments, and then two buttons (which are disabled until they completely fade) and, finally, animations of molecules that disappear endlessly on the loop. Then the page remains ambient until the user clicks one of the buttons.

I have four levels on the main timeline - Actions, Buttons, Molecules and Headers. In each of them there are corresponding images and animations.

I want to encode it so that each is played sequentially after the other, but it's really hard for me to access other time frames through AS3.

I currently have this at the Actions level:

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 follows clearly that I am marked by certain events on each timeline, and I want them to play upon completion.

The problem is to know what to put before the ".currentFrame" in each instance, and I cannot find it anywhere! So far I have managed to get using "this" and "MovieClip (this.root)", but I need to learn how to reference these built-in timelines to make it work. I tried these codes with "trace" and it seems to work fine, so I assume this is a problem.

+4
source share
1 answer

First of all, if you have code in the main timeline instead of MovieClip(this.root).currentFrame , you can just use currentFrame , since you are referencing the object the script is installed on.

Secondly it

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

just makes NRPSText_mc stay on the "NRPSFadeIn" label, as it is called every frame.

Thirdly, if you have a movie clip on the scene and you set its instance name, you can refer to its timeline from the parent area (main timeline) to that instance name, as well as to NRPSText_mc.gotoAndPlay("NRPSFadeIn") . If you have an INSIDE script, the movie clip simply uses gotoAndPlay() and currentFrame , because you are in the same object as the script.

Also you do it a little wrong. A general approach is to use timeline animations or some kind of twin library like TweenMax . Since you are using the Flash IDE, the right way to do the same would be to: create separate movie clips with any animation for your objects that you want; place them on the main timeline, which received its own animation with these clips; on any frame that you want to control with your internal clips, set individual scripts using stop() , gotoAndPlay() , etc.

If you want to receive notifications when a clip has finished playing, use AS3 events. For example, if you got a movie clip named mc , add a script to the last frame of dispatchEvent(new Event("stopped!")); stop(); dispatchEvent(new Event("stopped!")); stop(); and on the main timeline

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

Thus, it is much simpler than checking the number of frames in each enterframe event.

+3
source

Source: https://habr.com/ru/post/1397517/


All Articles