Scripted loops, questions from newbie

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.

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…

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.

I feel a little dumb, not used to that.

I understand…

regards

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

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

ARGH!!! :scream:"

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:

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

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

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;
}

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

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.

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);
	}
};

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

You forgot to increment :slight_smile:

There:

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

*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… :stuck_out_tongue:

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

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

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

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:

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…

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)

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.

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

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:

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.

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

You will see how coordinates are then.

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

VIEW GRID 2

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

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