Request: AS2 gotoandplay but smooth?

A place for tutorials on how to get the most out of Flash

Request: AS2 gotoandplay but smooth?

Postby Mr D » Thu Mar 14, 2013 12:28 am

Well here I am again...begging for advice. Anyways here goes.

In my animations I use a lot of loops and that is by doing "command on the last frame" = gotoandplay("beginning of the loop"). And If I press the button than gotoandplay(frame after the loop). But the problem is that because of this the animation is not smooth and just jumps to the frame I want to continue from. Is there a way how to (by pressing the button) finish the loop that the animation is in and than move on? I do think that this is used in the LoK game but I have no idea how.

Thanks in advance (if anyone is still around tutorial section :P)
1 game (oh I mean story slideshow -_-) and 5 flash loop FINISHED...fuck yea
My mini flashes link : http://legendofkrystal.com/forum/viewto ... f=7&t=1972
Also I am working on a project right now.But remember, it's a secret to everybody >:D
User avatar
Mr D
 
Joined: Tue Jun 01, 2010 12:44 am
Location: Alphabet

Re: Request: AS2 gotoandplay but smooth?

Postby OwnerOfSuccuby » Thu Mar 14, 2013 1:20 am

There are a lot of ways for doing it. For example - ... but as i understand you need it for animation not for games like ... action game where you run with some guy and try to kill or rape them all ? :mrgreen: :roll:

If so - for example you have some code on frame X.

You make variable for example Y on the first loop of frame and make it = 0 or for example false.

After you code on Frame X - you write this:

Code: Select All Code
If (Y==0){gotoAndPlay(Number of frame where it start loop);}
else if (Y==1){{gotoAndPlay(Number of frame you need after press button);}


And on press button for example you make his - you do not wright gotoandPlay in it you wright this:

Code: Select All Code
on (press) {
Y=1;
//and for example you can make button invisible like this:
ButtonName._visible=false;
//or ButtonName.visible=false; - i little forget AS2 syntaxis some times - ButtonName - is the name of button that you wright on it's name panel or i do not
//know how to say it: "name 2" on my picture
}


http://ownerofsuccuby.narod.ru/Testovie ... Symbol.png

You can ask me if it will be some problems - some of possible questions can be in this topic:
viewtopic.php?f=29&t=2370
If i will not on forum for some time (4 AM now =)) so i am going to sleep soon :mrgreen: )
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Request: AS2 gotoandplay but smooth?

Postby GoRepeat » Thu Mar 14, 2013 2:19 am

1) Break all your loops into their own movie clips so that the naturally loop without the need of a "gotoAndPlay" command at the end
2) Put them in sequential order in a new movie clip with a stop(); command on each
3) On the last frame of each loop put the code:
Code: Select All Code
if(this._parent.cont){
     this._parent.cont = false;
     this._parent.nextFrame();
}

4) on a new layer in the new compiled movie clip put the code:
Code: Select All Code
var cont:boolean = false;
var trig:boolean = false;
onEnterFrame = function(){
     if(Key.isDown(*insertASCIIKeyCodeHere*)){
          trig = true;
     }else{
          if(trig){
               trig = false;
               cont = true;
         }
     }
}


Each loop will play and check on the last frame to see if the key was hit, if so, it will go to the next loop in the sequence, otherwise it will just continue looping.

There are better ways to do it, but that is pretty straight forward and easy. If you have nonsequential loops (the full thing jumps around) then instead of this._parent.nextFrame(), you would put in whatever control for it to detect where it is supposed to be going. Usually a seperate switch function.


The key in the example is set to Spacebar:
Click to Play
(Javascript Required)

example.swf [ 4.96 KiB | Viewed 2666 times ]

Attachments
example.zip
(9.59 KiB) Downloaded 24 times
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Request: AS2 gotoandplay but smooth?

Postby Mr D » Thu Mar 14, 2013 2:42 am

Ok tried it and failed but lets see if I understand this correctly.

1st: the Y has to be 0 .Have no idea how to set it to 0 -_-
2nd: {gotoAndPlay(Number of frame where it start loop);} means I have to pick the number of the frame where the loop starts and not what I named it
3rd: the Code: If (Y==0){gotoAndPlay(N..... has to be on the last frame I want the 1st loop to repeat from.
4th: on (press) { Y=1; .Will change the Y from 0 to 1 and the animation will go past the 1st loop to the 2nd loop without jumping straight there

Do I understand it correctly?
Btw I dont know why I would want the button to be invisible.

EDIT: well this is awkward. I posted this before seeing Gores post, But I did read it now so here are some things. I do not understand the code but I am sure I can easily just duplicate and apply it from the example. But now the problem is that I would be unable to make the flash go to the beginning after all the loops are finished. And I need actual buttons and not just keyboard buttons.
1 game (oh I mean story slideshow -_-) and 5 flash loop FINISHED...fuck yea
My mini flashes link : http://legendofkrystal.com/forum/viewto ... f=7&t=1972
Also I am working on a project right now.But remember, it's a secret to everybody >:D
User avatar
Mr D
 
Joined: Tue Jun 01, 2010 12:44 am
Location: Alphabet

Re: Request: AS2 gotoandplay but smooth?

Postby KaTsuO_O » Thu Mar 14, 2013 8:12 am

In the button:
Code: Select All Code
on (release) {
proceed = true
}


On the last frame of each loop:
Code: Select All Code
if (proceed == true) {
proceed = false
} else {
gotoAndPlay("first frame of the loop")
}


You don't need to add "proceed = false" on the first frame, because "proceed" won't be either true or false from the beginning. "proceed = false" resets the variable so that the next loop will loop as well. You don't need a "gotoAndPlay" under "proceed = false" because it will just keep playing in to the next loop, since nothing is stopping it.
Last edited by KaTsuO_O on Thu Mar 14, 2013 2:55 pm, edited 2 times in total.
Don't create a porn game if you're only interested in porn.
Wise words regarding criticism http://www.youtube.com/watch?v=-98ZFl1sKt4
User avatar
KaTsuO_O
 
Joined: Tue Nov 02, 2010 6:03 pm

Re: Request: AS2 gotoandplay but smooth?

Postby OwnerOfSuccuby » Thu Mar 14, 2013 12:26 pm

Try to look this one i take this example ffrom LoK game (Flash CS4):
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Request: AS2 gotoandplay but smooth?

Postby GoRepeat » Fri Mar 15, 2013 1:26 am

If you are using buttons it is even easier, like Kat said, just change the code on the button's frame to:

Code: Select All Code
myButtonName.onRelease = function(){
     cont = true;
}


There ya go. I still disagree with using one massive animation and looping with gotoAndPlay. Trust me, trust me, it will lag things down significantly. One of the biggest performance discoveries I had with Sakyu. Make each loop its own animation then have each on its own stopped frame of a new object and control it from there.
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Request: AS2 gotoandplay but smooth?

Postby OwnerOfSuccuby » Fri Mar 15, 2013 1:56 am

By the way - interesting idea. Can you please post some example (*fla and *swf - for example with out real animaton just recktangles) of what you are talking about - becouse i little can not understand you (sorry for my bad englesh again :cry: :roll: )
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Request: AS2 gotoandplay but smooth?

Postby Mr D » Fri Mar 15, 2013 2:58 pm

Well the LoK method worked, so I will go with that one for now. Sorry Gore but I am a bit too dense to understand your method (to advanced and I have no real codding education). And I think I do not need to post an example for OwnerOfSuccuby now because the previous LoK flash is exactly what I wanted to achieve (the smooth transition from one loop to other).

Once again thank you for all your help.
1 game (oh I mean story slideshow -_-) and 5 flash loop FINISHED...fuck yea
My mini flashes link : http://legendofkrystal.com/forum/viewto ... f=7&t=1972
Also I am working on a project right now.But remember, it's a secret to everybody >:D
User avatar
Mr D
 
Joined: Tue Jun 01, 2010 12:44 am
Location: Alphabet

Re: Request: AS2 gotoandplay but smooth?

Postby OwnerOfSuccuby » Fri Mar 15, 2013 4:21 pm

Mr D sorry ;) but the question about *.Fla was to Gorepete - becouse i have some problem with gotoAndPlay too :mrgreen: - a long long LOOOONG :lol: time ago i made this animation:

And as you can see it is light version :mrgreen: :roll:

And if it is light it means that it was full version :lol: with more water animation and etc. But it lugs so hard that i have to restrct her :(

And i try to find solution from that time how to use less COU for thingh like that but can not get idea how to work with objects and do not use to much CPU :cry:
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Request: AS2 gotoandplay but smooth?

Postby Mr D » Fri Mar 15, 2013 5:22 pm

Oh ok. I thought it was a bit odd. Well I hope Gore can help you than :D
1 game (oh I mean story slideshow -_-) and 5 flash loop FINISHED...fuck yea
My mini flashes link : http://legendofkrystal.com/forum/viewto ... f=7&t=1972
Also I am working on a project right now.But remember, it's a secret to everybody >:D
User avatar
Mr D
 
Joined: Tue Jun 01, 2010 12:44 am
Location: Alphabet

Re: Request: AS2 gotoandplay but smooth?

Postby GoRepeat » Sat Mar 16, 2013 3:17 am

I think when you make one huge animation and use gotoAndPlay, flash has to load the entire movie clip and constantly scan it for the correct labels, which starts to generate lag once it gets big enough. If you make each loop its own movie clip and use a container object to control what is playing, then it only has to load the current loop and doesn't have to worry about scanning through 1000 frames for labels. That is just my theory from my own experience though.

And no worries D - I used to use the same object oriented code too. Recently I have moved towards using AS2 functions instead of putting code directly on objects because it does end up making things cleaner in the long run. It is just an extra step in the language that you have to get used to.

For example, putting:
Code: Select All Code
onRelease{
     gotoAndStop("Derp");
}

on a button is the same as putting:
Code: Select All Code
theButton.onRelease = function(){
     gotoAndStop("Derp");
}

on the main timeline. If you have a lot of stuff going on, it lets you consolidate actions and prevents the "where did I put that code?" bug researching dilemmas.
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass


Return to Tutorials



Who is online

Users browsing this forum: No registered users