Basic ActionScript help

I made and fla which thus far has 2 movie clips (it will have more). I want one clip to begin at the outset, the next when the first has concluded. Later, other clips will be following these two in order as each ends. Right now I put the two clips on different layers in the main timeline, but considering what i’ve read recently in my books, I think i’m reverting to old, non-ActionScript habits. I’m just not sure.

Each movie clip is 50 frames long.

I would appreciate a jumpstart on how to begin the first one with actionscript (as it is, it’s starting right out to play), and where to put the 2nd clip (it’s own layer as I have it??) OR how to code it to begin as the first ends.

Both movie clips MUST have an “instance” name. If you don’t know what that is, then you should go and read my pages starting at http://www.centerspin.com/tutorial/level1/101page1.htm

once you have given each an instance name, you can continue. For the sake of these examples, I’m going to use the names, “myMovieClip1” and “myMovieClip2”.

Select the first movie clip, and double click on it to go into “edit in place” mode.

If there is not a blank layer just for actionscript, create one now. Open up you’re “Actions” panel. Select the first frame of the action script layer and type this into the panel.

stop();

This prevents the movie clip from playing right off the bat.

Repeat this process for the second clip so that it too has a stop(); method.

Now. in clip one, you want to select the last frame of this action script layer and place a keyframe there. menu option “Insert/blank keyFrame”. Select this keyframe and type in the following code in the action script panel.

_parent.myMovieClip2.play();
stop();

what this is doing is saying… "look in the timeline that contains me, for an object called myMovieClip2, and make it start to play. Also, stop me from playing any more.

This will only work if myMovieClip2 exists at the time that this command takes place, so make sure that both movie clips exist on the main timeline at once.

You can also have the movie clips control the main timeline, with any of the following sorts of commands.

_parent.play();

_parent.stop();

_parent.gotoAndPlay(14);

_root.gotoAndStop(56);

in this case, _root acts the same way as _parent, but technicaly it’s different. Since movie clips can be placed inside each other, you can have levels upon levels of them each inside another. The _parent refers to the timeline which contains whatever is calling it, but the _root refers to the main timeline from where ever you may be in the structure of your movie. Since both movie clips are on the main timeline, any calls to either _parent, or _root will be the same thing for all intents and purposes.

Hope that helps a bit. If the above doesn’t then my tutorial pages should. I go over OOP and dot syntax calls in there.

Dear David,

Thank you for taking the time out of your day to help me. I was able to do exactly as you said and it works perfectly.

The book(s) I’ve used have done well to teach me to understand ActionScript, but my brain is still at the point of only understanding and not producing. I’ve said before, it’s like understanding a foreign language in another country but not being able to speak yet yourself.

I was so lucky to happen upon this forum. Thank you again.

         linda

You’re quite welcome. Nothing pleases me more than seeing an explination work on the first try. :slight_smile:

I know exactly what you mean about understanding but not being able to ‘speak’ it. You’ll get it as time goes on. Even now, people like Pom and Supra put me to shame with what they know how to do. Understanding is really the most important part though. You wouldn’t believe how much of my own scripts are simply sections of other people’s scripts cut, pasted, and edited to fit my plan. But that’s the nature of programing… cut and paste. (giving credit of course)

Have fun… and feel free to ask questions… we’re here to help.

As I said… everything went perfectly. Now, the question is the following.

using shorthand, my clips are named
myMovieClip1, myMovieClip2, myMovieClip3, myMovieClip4, etc…

Now, in my fla, the order of these is something like

      1
      2
      3
      4
      3
      5

ok, I added the extra actionscript layer as you said, and in the last frame of each movieclip I put the _parent.myMovieClipx.play(); line, followed by the stop();

works perfect.

However, what happens when I want a second instance of the same movie clip. I DID give it a different instance name. I used that 2nd instance name in the previous movieclip (for our example, i used myMovieClip4’s last frame to call for myMovieClip3 (using 2nd instance name).But what happens to the actionscript in that repeated second instance of the movie clip3? It’s referring in the last frame to a clip I wanted it to move to before(4), but now I want it to skip to 5. I realize I can make a different movie clip, but… is that the only way? I thought I can reuse clips. I don’t see where or how to alter the actionScript short of making a separate clip in my library. Is that what is necessary? thanks again.

gets a little tricky when you get into that. What you would do is change the code in that movie clip. Funny, but in your example, though you were using x as a statement of ‘whatever I put here’ it’s closer to the answer than you would think.

do you know how to add code to the outside of movie clips? There is such a thing as an onClipEvent(){} which is placed on the outside of movie clips the same way you place code on buttons. Select the movie clip with the action panel open and you can attach code to the outside of the clips. Now interestingly enough, when you set a variable in this method, the variable is avaliable to any code inside that clip.

So

change the code in the clip to this

_parent[“myMovieClip”+mcNumber].play();

then on the outside of the clip you can place this.

onClipEvent(load){
mcNumber=1;
}

You’ll see that this movie clip now starts the myMovieClip1 playing.
Change it to

onClipEvent(load){
mcNumber=6;
}

and it will start the number 6 clip instead.

Using this method you can even set the variable at run time dynamicaly just by calling out to the clip and setting it like so

_root.myMovieClip4.mcNumber=8;

You could use the same clip over and over this way in a number of places, changing the variable to your liking.

This one i’m going to study. Back to the chapter on variables. The brackets in your answer jogged my memory about arrays too. This is the perfect example of crossing a bridge between a textbook example and putting some knowledge to use. It always seemed easier for me to absorb the book… but using it… a different matter.

Thank you (again) . I think I can do this now, with your information.

     Linda

Well, I tried.

I am not sure where to put the variable. In your note, you used the example

onClipEvent(load){
mcNumber=1

Well, I was not sure WHERE (or, sigh, HOW) to set the variable in the first place for the repeating movieclip. If I have two instances of a movieclip with different instance names, located on the main timeline, and I highlight either of them, I don’t see a place in the properties window to set a variable.

I’m missing something that I may have read about, since it’s all familiar, but I can’t quite get it correct yet.

thanks…

the onClipEvent(){} is used in the Action panel.

Open the action panel first.

Select the movie clip.

Then enter the onClipEvent(load){}

onClipEvents act as if they are on the timeline of the movie clip that they are attached to, but, they opperate a little like buttons in that they ‘do’ their script whenever certain things occure with the movie clip

onClipEvent(load){} - do this action when the movie clip loads.
onClipEvent(enterFrame){} - do this action whenever this movie clip’s play head enters a frame on it’s timeline.
onClipEvent(data){} - do this action whenever this movie clip finishes receiving data from an outside source.

There are other on clip events as well, but those three are the most popular that I’ve found.

As I said. These are just like button scripts except they can only be used on movie clips. Just like button scripts wont work in a frame action, or if you attach them to a movie clip. You’ll get an error.

So the nature of the example is… you have the same movie clip that is reliant upon a variable to call it’s play command. That variable, even though it’s set on the outside of the movie clip, still acts as if it’s in the movie clip.

If you still can’t get it. (it can be tricky) I’ll send you an example of some on clip events and instructions on how to look at the actions.

ok…thank you so much… I’ll get back to you soon as I work on it! :slight_smile:

I’m determined… just not proficient :wink: