Actionscript 3 - lock the code from restarting while it loops - actionscript-3

I am making a boardgames in flash, with a background with moving objects.
It goes on repeat, so they dont stop on the last frame, which in this case is 60 frames. Only problem is, the actionscript code which has its own layer, and exists on frame 1, resets every time it starts over again, logically enough. But then I loose all the data I´ve gained over the time of 60 frames.
Is there a way I can make the actionscript code unbound from the objects loop?
Cheers

On the last frame of your animation, add a bit of AS3 code to force skipping frame 1:
gotoAndPlay ( 2 );
When the playhead reaches the last frame, this line will execute and your animation will restart at frame #2, skipping the code on frame #1.

Related

Actionscript-3 looping issue--Adobe Animate CC

My employer decided they wanted me to start doing animation with Adobe's new "Animate CC" application. My issue is that I don't know how to loop my animation outside of the Adobe Animate environment. I am new to Adobe Animate CC and ActionScript, unfortunately, so I will probably need a relatively basic answer to understand why my solution isn't working. From what I can tell, my ActionScript code is being ignored by the IDE completely.
In the IDE and in the browser test command, the animation plays beyond frame 100, to the end, and then flashes a frame of white before repeating. I need it to loop without this white frame interrupting the screen, whether that be through a loop or some other means that I'm just not aware of.
For context: my project has about 100 layers of content and I'm unfamiliar with how this program works. I've thoroughly searched the web for tutorials on how to do what I need to do, but I've come up empty handed.
I have an actions layer among my motion tweens and other layers
https://gyazo.com/6e0b8502d98b6c9903bb96ac3a939bae
I've been trying to use gotoAndPlay(0) at frame 100 to start the animation over from the beginning.
https://gyazo.com/704ee7158bae6dfd149b6283cfa33451
Basically, how do I use Action-Script in Adobe Animate CC in order to infinitely loop my animation until closed?
Thanks everyone.
Your flicker may be a result of having an extra blank keyframe on one of your layers.
Assuming that you don't have any additional scripts to stop your animation (e.g. stop()), the Timeline should loop automatically whether your animation is inside a MovieClip or on the main Timeline. You shouldn't have to put any script on your timeline or in a separate AS file to make an animation loop. I would suggest this method.
Additionally, although you have the code specifying that you want it to go the first frame, it will ignore your call because the timeline is still playing and therefore the priority. One way you can combat this is by adding a stop(); function and a delay timer that contains your gotoAndPlay(0) function. This will take focus away from playing the Timeline and will allow you to execute your script. I wouldn't suggest this method because it seems a bit redundant.
However, if you're curious one way that you could approach this is shown below, simply add this script to the frame you want the animation to restart at.
//Stop the Timeline
stop();
//Create a delay timer for 5 miliseconds that is executed once
var timer:Timer = new Timer(5,1);
//Add an event listener that calls once the timer is complete
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
//Start the timer
timer.start();
//Timer handler that is called once the delay timer is complete
function timerHandler(event:TimerEvent){
//Go to and play the first frame
gotoAndPlay(0);
}

Looping frames, and using keyboard listener to continue to next frames

Im still rather new to flash.
Im currently working on animation that I want to use to present my work with. I want to run short clip, consisting of 180 frames, that continually loops while I talk. Then when I press left key on the keyboard, the animation must continue.
I can get to loop the clip, using gotoAndPlay, but as soon as add the addEventListener. The I tried to incorporate a Boolean value, but that fails as well. Any help/suggestion would be greatly appreciated
Should be as simple as creating a new symbol that will contain your animation of 180+ frames. Inside this symbol/movieclip you can add code on frames which you need to loop (F9). So on frame 180 you'd write gotoAndPlay(1);. And when you need to continue from the parent call clip.gotoAndPlay(181);

Actionscript 3 - Playing Textbox Animation in Movieclip [repeat]

So I've got a movieclip, I've got another movieclip in that so I can tween it.
I've got the following code
animText.displayedText.info_txt.text="YOU LICKED A TOILET BRUSH";
animText.gotoAndPlay(1);
It starts from frame 1 each time the code is called...
but, if you call the code twice, a few seconds after the 1st...
it doesn't start from the beginning, but instead just ignores the second one.
Surely, since there is a gotoAndPlay && changing the text, it should start again.

Actions are assigned to wrong keyframe in Flash CS5

I am working with Flash CS5, and haven't been using Flash since the age of AS2.
I have a movieclip symbol in which I have an Actions layer, in which I have a keyframe in frame 1 and one in frame 20. Each of these should have a stop(); action assigned, but when i select the one in frame 20 and start writing, the little "a" appears on frame 1 of another layer. When I make a keyframe in frame 20 of that layer and try to assign actions it yields the same result. They appear on frame 1.
Is this a bug or am I missing some vital information about AS3?
AS3 is in fact more picky (for good reason) about how the code is implemented.
You need to select the keyframe you are intending to put code into, and then use your actions window. And as Markus commented, make sure you're using keyframes, and not empty frames. If you try to write code into an empty frame, it will default it to the most recent keyframe.
Furthermore, If you have multiple layers and say, your code is on layer2 and your objects on layer1, if you have keyframes on layer1, and intend to enter code at frame 20, but your layer selection is layer2, it will yield the same result described above. You'll have to make sure the correct layer is active. The actions window will only display the code from the current layer's most recent keyframe.
Hope that clears some things up!

AS3 save previous frame while going in next to do something

Is posible something like this: in frame1 I have some user interaction (drag drop graphics etc), when user click some button I open frame2 or frame3 where are fields for taking some input from user, then when user finish, I back him to frame1 but frame is not "reset"? I tried what described here, and I can even send data from frame 2 to frame 1 using global vars, but frame 1 is "reset" all user actions are clean, so is there a way in this situation to keep frame1 in memory or something?
Previous or next go to a frame if the frame is being initialized is natural. There's no way to save it. In other words, move the frame is The following concepts, removeChild(previous-stage), addChild(next-stage)
In my experience, the script code to control the frame, increasing complexity are highly undesirable. Maintenance is difficult and in the future, the readability of the code is very poor. Recommend to handle than that in a single frame. Something like a single frame of the object location, size, status, and stored as a variable because it can restore it, it's more reasonable to think that.
If you are working with Flash & AS3 together you can put the code:
gotoAndStop(3); // 3 is the number of the frame
If you are using:
gotoAndPlay(3); // it will begin to play the frames from 3 till the timeline finds a stop mark.
So, you'll need to put a stop on the frame you want.
e.g. stop();
check out this tutorial: http://www.youtube.com/watch?v=9N9vE7wjoc4