# Scripted loops, questions from newbie

**URL:** <https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974>\
**Category:** Uncategorized\
**Created:** [February 6, 2003, 10:41pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974 "2003-02-06T22:41:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimw00d](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@jimw00d](https://forum.kirupa.com/u/jimw00d)\
**Post date:** [February 6, 2003, 10:41pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/1 "2003-02-06T22:41:45Z")

</div>

I am experimenting with drawing methods in flash mx and I am trying to use the code below to draw a rectangle and then adjust the coordinates of each duplicated mc.

this.onEnterFrame=function(){  
mc=createEmptyMovieClip(“mc”, 1);  
mc.lineStyle(1, 0xFFFFFF, 80);  
mc.moveTo(100, 100);  
mc.lineTo(150, 100);  
mc.lineTo(150, 130);  
mc.lineTo(100, 130);  
mc.lineTo(100, 100);   
}  
for(x=0;x\<100;x++){  
duplicateMovieClip(“mc”,“dupMc”+x,x);  
\_root[“dupMc”+x].\_y=x\*5;  
}

Can anyone suggest what I am doing wrong??

It has been suggested that scripted loops cannot be used to modify visual events over time.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2003, 10:48pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/2 "2003-02-06T22:48:22Z")

</div>

Ok, I am in a rush, but I will try to explain.

Your are duplicating your mc clip, which is an EMPTY movie clip.

Therefore you won’t see anything.

You used the drawing API on the empty movie clip, but that is just on that empty movie clip, not the duplicated ones. You will have to redraw your block for each empty movie clip.

And if you have to do that, why duplicate your clip? Just dynamically recreate an empty movie clip and redraw your lines.

Try this…

```php
for (x=0; x<100; x++) {
	_root.createEmptyMovieClip("mc"+x, x);
	myMc = _root["mc"+x];
	myMc.lineStyle(1, 0xFFFFFF, 80);
	myMc.moveTo(100, 100);
	myMc.lineTo(150, 100);
	myMc.lineTo(150, 130);
	myMc.lineTo(100, 130);
	myMc.lineTo(100, 100);
	myMc._y = x*5;
}

```

Alright, I gotta go…

If I am wrong in anything I said, or in my method, I am sure Senocular will belittle me (which is a good thing).

Later and good luck, I hope that code works.

OH yeah and note: Your are making your line white (FFFFFF) so make sure your background of your movie isn’t white.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2003, 10:56pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/3 "2003-02-06T22:56:40Z")

</div>

I feel a little dumb, not used to that.

I understand…

regards

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2003, 12:45am UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/4 "2003-02-07T00:45:47Z")

</div>

Don’t feel dumb. I made the same mistake before.

I was like… "WHY ISN’T THIS PIECE OF CRAP WORKING!!!

ARGH!!! 😱"

Then I tried a method similiar to the above posted and it worked.

I am assuming this worked in your case as well?

The drawing API can be a pain when it wants to be, but don’t let it get you down, just show it whos boss :evil: :bad:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2003, 7:34am UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/5 "2003-02-07T07:34:30Z")

</div>

Nope, haven’t tried it out. I see no reason why it shouldn’t work as to how I want it to.

I wonder if the overall effect would be easier to create in swift 3d rather than messing with the api drawing tools. Swift 3d seems to easy for me, I like it a little testing.

I wanted to create a scene with a small box that gradually moves centre stage as it gets larger, a sort of 3d effect, with the previous boxes having an increasingly larger alpha value to give the impression of a box sort of flying in.

I hate using tweening for some reason. I’ll stick with api.

regards

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2003, 7:40am UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/6 "2003-02-07T07:40:24Z")

</div>

Hrmm… Ok… again untested, but if I get what your saying try something like this…

```php
for (x=0; x<40; x++) {
	_root.createEmptyMovieClip("mc"+x, x);
	myMc = _root["mc"+x];
	myMc.lineStyle(1, 0xFFFFFF, 100);
	myMc.beginFill(0xFFFFFF, 100);
	myMc.moveTo(100, 100);
	myMc.lineTo(150, 100);
	myMc.lineTo(150, 130);
	myMc.lineTo(100, 130);
	myMc.lineTo(100, 100);
	myMc.endFill();
	myMc._y = x*5;
	myMc._xscale = myMc._yscale=x*5;
	myMc._alpha = x*.5;
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 10:06am UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/7 "2003-02-10T10:06:03Z")

</div>

The effect your code created was great. My only issue is that I wanted the user to be able to see the effect as an animation.

Drawing with your code produces an effect that is too quick for the human eye. Any ideas on how to produce the same effect over say 40 frames.

I have done a fla but I am sure there is a better way of achieving what I want.

If you feel like giving a hand on this one, that would be great.

Regards

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 6:22pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/8 "2003-02-10T18:22:55Z")

</div>

Well your example didn’t work for me, I did come up with this partial method using setInterval(), but I can’t get it to stop duplicating! grrr. I tried clearInterval() but it didn’t work, I don’t get it! (I was never good with that setInterval and clearInterval stuff to begin with)

Well if you want to mess around with what I have so far, just put this in Frame 1.

```php
maxClips = 10;
i = 0;
function createClip() {
	_root.createEmptyMovieClip("mc"+_root.i, _root.i);
	myClip = _root["mc"+_root.i];
	myClip.lineStyle(1, 0xFFFFFF, 100);
	myClip.beginFill(0xFFFFFF, 100);
	myClip.moveTo(100, 100);
	myClip.lineTo(150, 100);
	myClip.lineTo(150, 130);
	myClip.lineTo(100, 130);
	myClip.lineTo(100, 100);
	myClip.endFill();
	myClip._y = _root.i*5;
	myClip._xscale = myClip._yscale=_root.i*5;
	myClip._alpha = _root.i*.5;
}
_root.onEnterFrame = function() {
	if (_root.i<=maxClips) {
		setInterval(createClip, 110);
	}
};

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 6:58pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/9 "2003-02-10T18:58:40Z")

</div>

I’m not getting anything with that script of yours, Lost. And if I may say so, you’re not using setInterval properly (or maybe you are but I’m misunderstanding the code).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 7:00pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/10 "2003-02-10T19:00:00Z")

</div>

You forgot to increment 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 7:03pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/11 "2003-02-10T19:03:08Z")

</div>

There:

```auto
maxClips = 10;
i = 0;
function createClip() {
	if (i<=maxClips){
		with (_root.createEmptyMovieClip("mc"+i,i)){
			lineStyle(1, 0xFFFFFF, 100);
			beginFill(0xFFFFFF, 100);
			moveTo(100, 100);
			lineTo(150, 100);
			lineTo(150, 130);
			lineTo(100, 130);
			lineTo(100, 100);
			endFill();
			_y = i*10;
			_xscale = myClip._yscale=i*10;
			_alpha = i*10;
			i++;
		}
	} else clearInterval(theInterval);
}
theInterval=setInterval(createClip, 100);

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 7:44pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/12 "2003-02-10T19:44:27Z")

</div>

> \*Originally posted by ilyaslamasse \*  
> \*\*And if I may say so, you’re not using setInterval properly (or maybe you are but I’m misunderstanding the code). \*\*

Well I did say I was never good with that whole setInterval clearInterval thing… 😛

And… 'DOH! I see what I did wrong.

BTW: you forgot to remove the myClip from the \_yscale.

```php
maxClips = 10;
i = 0;
function createClip() {
	if (i<=maxClips) {
		with (_root.createEmptyMovieClip("mc"+i, i)) {
			lineStyle(1, 0xFFFFFF, 100);
			beginFill(0xFFFFFF, 100);
			moveTo(100, 100);
			lineTo(150, 100);
			lineTo(150, 130);
			lineTo(100, 130);
			lineTo(100, 100);
			endFill();
			_y = i*10;
			_xscale = _yscale=i*10;
			_alpha = i*10;
			i++;
		}
	} else {
		clearInterval(theInterval);
	}
}
theInterval = setInterval(createClip, 100);

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 11, 2003, 9:07am UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/13 "2003-02-11T09:07:14Z")

</div>

Not sure where any of this is going, probably nowhere. Thankyou for the help to date. After a little tweaking I have got the effect I need, although I am having trouble with repositioning the start point of the effect, besides altering the co-ordinates of the original box, which has little overall effect.

Also, I would like to address the last box of the animation, I assume it would be Mc9. I would like to set the box’s rotation property. One definate problem I think I will have is removing the box from the loop so that additional properties can be altered. On a previous experiment the loop always tried to pull the box back into its original location, thus producing a shaking box.

I’ll give it thought today but any suggestions would be great.

As you are both, in my opinion at least, vastly more knowledgeable than I, would it be appropriate to discuss whether a tweened animation would be better to produce (file size effects notwithstanding) or using something like swift 3d??

Best Regards

:beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 11, 2003, 6:04pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/14 "2003-02-11T18:04:29Z")

</div>

You don’t need to seperate the last clip, just target it when they are all loaded.

I modified the script a bit to draw squares with a centered anchor point instead of in the upper left corner like you had…

```php
maxClips = 10;
i = 0;
function createClip() {
	if (i<=maxClips) {
		with (_root.createEmptyMovieClip("mc"+i, i)) {
			lineStyle(1, 0xFFFFFF, 100);
			beginFill(0xFFFFFF, 100);
			moveTo(-50, -50);
			lineTo(-50, 50);
			lineTo(50, 50);
			lineTo(50, -50);
			lineTo(-50, -50);
			endFill();
			_y = _x=i*10;
			_xscale = _yscale=i*10;
			_alpha = i*10;
			i++;
		}
	} else {
		clearInterval(theInterval);
		_root["mc"+maxClips].onEnterFrame = function() {
			this._rotation += 10;
		};
	}
}
theInterval = setInterval(createClip, 100);

```

\_root[“mc”+maxClips].onEnterFrame = function() {  
this.\_rotation += 10;  
};

That is the script that rotates the clip. It is dyanmic because \_root[“mc”+maxClips] always targets the last clip no matter how many clips you use.

If you don’t want something to happen onEnterFrame just use \_root[“mc”+maxClips].\_property (\_property is what you replace what you want to go there)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 12, 2003, 8:24am UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/15 "2003-02-12T08:24:19Z")

</div>

Thankyou very much for your help. The only question I have is the matter of the anchor point. Was it only the co-ordinates of the box that you’ve changed. I can’t discern anything else in the script that would alter this anchor.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 12, 2003, 8:27am UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/16 "2003-02-12T08:27:06Z")

</div>

Yeah that is all I did… I edited the coordinates for which the lines were drawn too because in your original script you had the anchor point in the upper left, so when you rotated it it made a HUGE rotation around, kind of like twirling a yo-yo, so I redrew the shape so the anchor point would be in the middle and it could spin like it was on an axis (sorta like a basketball spinning on a finger).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 12, 2003, 12:43pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/17 "2003-02-12T12:43:31Z")

</div>

OK, but how does simply changing the co-ordinates of the mc adjust the anchor point. Surely by making the adjustment to the co-ordinates you would end up with the same problem as before.

The methodology of creating the clip and then moving it to a desired location is the same, right??

100,100 and -50,-50 would surely have the same effect. Why does your method alter the anchor point whereas mine does not.

I can take this at face value but it is better for me if I try to understand.

:q:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 12, 2003, 8:21pm UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/18 "2003-02-12T20:21:18Z")

</div>

Well think of it as a grid.

You have 4 quadrants, the

## (-x,-y) | (+x, -y)

(-x, +y)| (+, +y)

And the center point it at (0,0) If you make it (-50, -50) you are starting the clip in the (-x,-y) zone, but if you start from (100,100) you are starting in the (+x,+y) zone which is off center from the clip.

I believe Flash is backwards with how the \_y works, so -y is up top and +y is down below.

I am in a rush so I might be confusing myself, or not explaining good, if you don’t understand I will come back when I have more time. Just let me know.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 13, 2003, 7:30am UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/19 "2003-02-13T07:30:15Z")

</div>

Ok, I drew up some images that maybe might help you better understand why I did what I did.

First check out the way the grid in Flash works when creating an empty movie clip symbol.

[VIEW GRID 1](http://www.8ballcreations.com/lostinbeta/banner/flashGrid.jpg)

You will see how coordinates are then.

Now, take a look at how I drew your square.

[VIEW GRID 2](http://www.8ballcreations.com/lostinbeta/banner/flashGridBox.jpg)

Do you notice how I drew the lines from points that surround the anchor point at (0,0)???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 13, 2003, 8:39am UTC](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974/20 "2003-02-13T08:39:21Z")

</div>

Yep,

all clear now. Thankyou for all your help.

My last and I mean last question on this is how in the next frame I would remove all on screen.

Since we’ve used createEmptyMovieClip, I take it we could use removeMovieClip(“mc”+i) or removeMovieClip(“mc”+maxClips")???

regards

[Next page](https://forum.kirupa.com/t/scripted-loops-questions-from-newbie/12974.md?page=2)
