ALL dynamic moving lines(help)

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)…


//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)?

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

*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.

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

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

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?

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


//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)

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.