Skip to main content
Participating Frequently
June 14, 2006
Answered

Problems with instances

I need a same action to occur for few movie clips. For example i have instances: P1 P2 P3 P4.
I tried:
Calling every one of them by one name.
Writing P[1,2,3,4]
Writing G = "P" +[1,2,3,4]

Can anyone help me?
This topic is closed to new replies. Start a new post to keep the conversation going.
2m91_2
2m91_2Correct answer
Inspiring
June 17, 2006
So you have an instruction that makes your clip move over time. that instructin works (looks like at least). Right?

You could put that instruction to any number of clips without problems. Right?

So what you want is puting said instruction on more than one clip without having to do son one by one manually? Right?

A loop would still do that. INstead of "doSomethingFunction()" you just would write:

for (var i = 0; i < 5; i++){
ParentMoviclipName["P"+i].onEnterFrame = function (){
this._x +=20;
}
}

8 replies

TeshlaAuthor
Participating Frequently
June 19, 2006
Thanks for the help, script was slightly diffirent but thanks to you i learne <<<The Loop>>>.
Translate
TeshlaAuthor
Participating Frequently
June 18, 2006
Sorry for this but i really need the answer.
Translate
TeshlaAuthor
Participating Frequently
June 17, 2006
I didn't mean frames that are in timeline. For example:
onClipEvent (enterFrame) {
something._x + = 20
}



So it will take 2 frames to move it by 40, 3 frames to move it by 60 (and so on) even if nothing is playing in the timeline. Thats what about i was talking (maybe this thing has other name that i do not know).
By the way i cant make anything with this loop, I guess i asked wrong. I dont need some sort of function to occur, I need that all movie clips with those instances would change their position.
Translate
2m91_2
2m91_2Correct answer
Inspiring
June 17, 2006
So you have an instruction that makes your clip move over time. that instructin works (looks like at least). Right?

You could put that instruction to any number of clips without problems. Right?

So what you want is puting said instruction on more than one clip without having to do son one by one manually? Right?

A loop would still do that. INstead of "doSomethingFunction()" you just would write:

for (var i = 0; i < 5; i++){
ParentMoviclipName["P"+i].onEnterFrame = function (){
this._x +=20;
}
}
Translate
TeshlaAuthor
Participating Frequently
June 17, 2006
I have a game where screen moves together with character (that means that all the obstances, enemies, floor and so on move to direction opposite of the one you pressed). And I want to save myself a lot of time. Because this loop that you teached me about will let me move all the pieces with writing one line instead of writingn 3 lines for each.
This is how my script looks now:

onClipEvent (enterFrame) {
if (Key.isDown (Key.RIGHT)){
_root.Floor1._x -= speed;
_root.Floor2._x -= speed;
}
}


The place i underlined shows Where I need to insert the loop cuz there will be many more Floor pieces.

P. S. Most of the script u wrote me I understand, but why do I need Parent Movie Clip Name?
Translate
2m91_2
Inspiring
June 14, 2006
for (var i = 0; i < 5; i++){
ParentMoviclipName["P"+i].doSomethingFunction();
}

Would do the trick.

It's called a loop.
Translate
TeshlaAuthor
Participating Frequently
June 17, 2006
I have one more question, does this loop take multiple frames or only one?
Translate
2m91_2
Inspiring
June 17, 2006
The loop executes in the one frame it is placed on. The comands issued within (e. g. play()) can effect any number of frames on that timeline or any other they are connected with.

If one of your movie clip instances isn't present at the frame where your loop is placed, no action on that clip can happen.
Translate