# ALL dynamic moving lines(help)

**URL:** <https://forum.kirupa.com/t/all-dynamic-moving-lines-help/29151>\
**Category:** flash\
**Created:** [August 22, 2003, 10:25pm UTC](https://forum.kirupa.com/t/all-dynamic-moving-lines-help/29151 "2003-08-22T22:25:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ironman](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Ironman](https://forum.kirupa.com/u/Ironman)\
**Post date:** [August 22, 2003, 10:25pm UTC](https://forum.kirupa.com/t/all-dynamic-moving-lines-help/29151/1 "2003-08-22T22:25:23Z")

</div>

## Aright, so I decided to make a movie that’s entirely done with ActionScript. Only problem I ran into is that it seems the dynamic movieclips are not using the main scene’s (x,y) registration points. Perhaps this is a very simple issue and I’ve just been thinking too long on it. Here’s my code (simply put in one layer with one keyframe)…

```auto

//move the movieclip
MovieClip.prototype.move = function(){
	this._y += this.movement;
	if(this._y >= 400){this.movement = -this.movement;};
	if(this._y <= 0){this.movement = -this.movement;};
}

//how many lines am I creating
var maxLines = 50;
for (var i=1; i<=maxLines; i++){
	//create new empty movie clip on main timeline
	mc=_root.createEmptyMovieClip( "line"+i, i );
	//get a random y value for our line's starting point within the new movieclip
	var randY = random(400);
	//get a random color for our line
	var randColor = "0x";
	for (var j=1; j<6; j++) {
		whichColor = random(2);
		if(whichColor){	randColor += random(F); }
		else { randColor += random(9); }
	}
	//draw a line in the movieclip
	with ( mc ) {
		lineStyle( 3, randColor, 100 );
		moveTo( 0, randY );
		lineTo( 500, randY );
	}
	//get a random speed from 1 to 15
	mc.movement=random(15)+1;
	mc.onEnterFrame=move;
}

```

* * *

When you create a movie clip with “createEmptyMovieClip”, what is the size of that clip? Is it the size of the stage or of only the object you create in the clip(as in traditional “static” design)?

---

<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:** [August 22, 2003, 10:27pm UTC](https://forum.kirupa.com/t/all-dynamic-moving-lines-help/29151/2 "2003-08-22T22:27:22Z")

</div>

not exactly sure. slap some \_root. infront of some of them and you should be good

By the way, use the [\<b\>\</b\>as][/\<b\>\</b\>as] tags for posting 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:** [August 22, 2003, 10:35pm UTC](https://forum.kirupa.com/t/all-dynamic-moving-lines-help/29151/3 "2003-08-22T22:35:31Z")

</div>

> \*Originally posted by Coppertop \*  
> \*\*not exactly sure. slap some \_root. infront of some of them and you should be good

By the way, use the [\<b\>\</b\>as][/\<b\>\</b\>as] tags for posting code \*\*

sorry about that… I went back and edited with the tags. Thanks for the info, however I am using some “\_root” tags to refer to the new movies.  
i.e.

```auto
mc=_root.createEmptyMovieClip( "line"+i, i );

```

I’m not sure where else I should add them.

---

<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:** [August 22, 2003, 11:04pm UTC](https://forum.kirupa.com/t/all-dynamic-moving-lines-help/29151/4 "2003-08-22T23:04:22Z")

</div>

Ah thats better. Now I can read it.

Well, looking at it I can see no problems, so I pasted it in FLash, and still have no problems. What is it thats wrong?

---

<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:** [August 22, 2003, 11:59pm UTC](https://forum.kirupa.com/t/all-dynamic-moving-lines-help/29151/5 "2003-08-22T23:59:50Z")

</div>

The problem I was having was with the lines going outside the movie scope. Actually, I introduced some additional code and fixed it myself :). Let me show you what I mean… here’s the new code

```auto

//move the movieclip
MovieClip.prototype.move = function(){
	this._y += this.movement;
	if(this._y >= 400-this.startpos){this.movement = -this.movement;};
	if(this._y <= 0-this.startpos){this.movement = -this.movement;};
}

//how many lines am I creating
var maxLines = 50;
for (var i=1; i<=maxLines; i++){
	//create new empty movie clip on main timeline
	mc=_root.createEmptyMovieClip( "line"+i, i );
	//get a random y value for our line's starting point within the new movieclip
	var randY = random(400);
	//get a random color for our line
	var randColor = "0x";
	for (var j=1; j<6; j++) {
		whichColor = random(2);
		if(whichColor){	randColor += random(F); }
		else { randColor += random(9); }
	}
	//draw a line in the movieclip
	with ( mc ) {
		lineStyle( 3, randColor, 100 );
		moveTo( 0, randY );
		lineTo( 500, randY );
	}
	//get a random speed from 1 to 15
	mc.startpos=randY;
	mc.movement=random(15)+1;
	mc.onEnterFrame=move;
}

```

What I did was keep track of each line’s initial starting position (as follows)

```auto
mc.startpos=randY;

```

Apparently flash dynamically creates movieclips to be the size of the stage or something? Run this code and compare it to the old.  
The old code went outside of my 550width x 400 height stage boundary while the new one does not.
