# What can I do with a gird?

**URL:** <https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342>\
**Category:** flash\
**Created:** [October 4, 2002, 4:38pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342 "2002-10-04T16:38:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Andy](https://forum.kirupa.com/u/Andy)\
**Post date:** [October 4, 2002, 4:38pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/1 "2002-10-04T16:38:24Z")

</div>

I just did ilyas’ grid tutorial, I took my time to fully understand the code. Now I got a whole lot of movie clips orginized in nice rows each with an individural name. What can I do now? I know a gird can do alot of things, I just dont know any of them. :-\ Can someone give me some additional code to mess around with, maybe explain it if it is confusing.  
Here’s what I got so far. (excuse my variable names 😏 )

gridy=30;  
gridx=30;  
num=0;  
for (var i=0;i \< 10;i++)  
{  
for (var j=0;j \< 10;j++)  
{  
mr.duplicateMovieClip(“mr”+num,num);  
mc=this[“mr”+num];  
mc.\_y=gridx_i+30;  
mc.\_x=gridy_j+30;  
stupid = Math.round( Math.random()\*0xFFFFFF );  
mybad = new color (\_root.mc);  
mybad.setRGB(stupid);  
num++;  
}  
}

---

<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:** [October 4, 2002, 9:21pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/2 "2002-10-04T21:21:00Z")

</div>

I’ll post something after the contest 🙂

---

<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:** [October 4, 2002, 9:29pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/3 "2002-10-04T21:29:49Z")

</div>

OK, what the hell. Something simple, if you use MX:

```auto
gridy=30;
gridx=30;
num=0;
for (var i=0;i < 10;i++)
{
	for (var j=0;j < 10;j++)
	{
		mr.duplicateMovieClip("mr"+num,num);
		mc=this["mr"+num];
		mc._y=gridx*i+30;
		mc._x=gridy*j+30;
		stupid = Math.round( Math.random()*0xFFFFFF );
		mybad = new color (_root.mc);
		mybad.setRGB(stupid);
		mc.onEnterFrame=function()
		{
			this._xscale=this._yscale=50*(1+Math.sin(this.a+=.2))+10;
		}
		num++;
	}
}

```

pom :asian:

---

<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:** [October 4, 2002, 9:36pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/4 "2002-10-04T21:36:07Z")

</div>

Or

```auto
gridy=30;
gridx=30;
num=0;
for (var i=0;i < 10;i++)
{
	for (var j=0;j < 10;j++)
	{
		mr.duplicateMovieClip("mr"+num,num);
		mc=this["mr"+num];
		mc._y=gridx*i+30;
		mc._x=gridy*j+30;
		mc.num=num;
		stupid = Math.round( Math.random()*0xFFFFFF );
		mybad = new color (_root.mc);
		mybad.setRGB(stupid);
		mc.onEnterFrame=function()
		{
			this._xscale=this._yscale=50*(1+Math.sin(this.a+=.2+this._num/100 ))+10;
		}
		num++;
	}
}

```

pom :asian:

---

<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:** [October 4, 2002, 9:42pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/5 "2002-10-04T21:42:06Z")

</div>

Hmm…

```auto
gridy=30;
gridx=30;
num=0;
for (var i=0;i < 10;i++)
{
	for (var j=0;j < 10;j++)
	{
		mr.duplicateMovieClip("mr"+num,num);
		mc=this["mr"+num];
		mc.starty=gridx*i+30;
		mc.startx=gridy*j+30;
		mc.i=i;
		stupid = Math.round( Math.random()*0xFFFFFF );
		mybad = new color (_root.mc);
		mybad.setRGB(stupid);
		mc.onEnterFrame=function()
		{
			this._x=this.startx+5*this.i*Math.sin(this.a+=.2);
			this._y=this.starty;
		}
		num++;
	}
}

```

I hope this will give you some ideas.

pom :cowboy:

---

<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:** [October 5, 2002, 2:37am UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/6 "2002-10-05T02:37:40Z")

</div>

Thx for that I’ll see what it does and then try to understand the code more. 🙂

---

<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:** [October 5, 2002, 9:42am UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/7 "2002-10-05T09:42:23Z")

</div>

Well, I didn’t add much. Just an onEnterFrame for each dot, and a sin function and voilà 🙂

---

<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:** [October 5, 2002, 5:22pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/8 "2002-10-05T17:22:15Z")

</div>

hey, pom… i have tried a bunch of times to get that effect where depending on your distance from a movie clip it will scale up or down… there are a couple of them in the grid contest thing… i was wondering how you do that… cuz every time i try it gives me this spasm and like grows bigger than the screen… can you please tell me how to do this?

---

<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:** [October 5, 2002, 5:31pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/9 "2002-10-05T17:31:32Z")

</div>

what i tried was i put this inside the movie clip…

```auto

onClipEvent(enterFrame){
	_xscale = Math.abs(_x - _xmouse);
	_yscale = _xscale;
}

```

[list]  
[/list]

it seems like if i take the absolute value of the distance from the x of the movie clip and the x of the mouse… it will always be ok… but once i get the mouse greater than the x… it spasms… and also… i dunno how to make it coincide with the y scale… cuz if i put the same thing pertaining to y… it scales all weird… i’m sure its much more complicated than i can come up with… i have no clue where to go from here…

---

<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:** [October 5, 2002, 5:44pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/10 "2002-10-05T17:44:12Z")

</div>

Well, you have to get the distance between the mouse and the mc. But your formula is wrong (incomplete):

```auto
var dx=_x-_root._xmouse;
var dy==_y-_root._ymouse;
var distance=dx*dx+dy*dy;
_xscale=_yscale=distance/500;

```

will do the trick. In fact, the distance is the square root of dx_dx+dy_dy, but this will work the same.

If you see nothing, decrease 500. If it moves too fast, increase it.

pom 😏

---

<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:** [October 5, 2002, 5:48pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/11 "2002-10-05T17:48:23Z")

</div>

Yeah, I learned that method after I posted my entries. I didn’t feel like going back and fixing all my files so I left them at my difficult way (I love doing things the hard way for some reason…just doesn’t make sense).

---

<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:** [October 5, 2002, 7:59pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/12 "2002-10-05T19:59:49Z")

</div>

thanks, thats great… what would i do if i wanted to make it scale up if you are closer… or down for farther away… i think i may want to use this method on a menu of some sort… where the buttons scale up when you get closer… your help is very much appreciated… i wish i knew as much about flash as you guys here…🙂

---

<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:** [October 5, 2002, 8:12pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/13 "2002-10-05T20:12:42Z")

</div>

To just scale on up and down, remove the xscale factors.

Something like this…

```auto
	var dy = this._y-_root._ymouse;
	var distance = dy*dy;
	this._yscale = distance/500;

```

---

<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:** [October 5, 2002, 8:14pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/14 "2002-10-05T20:14:32Z")

</div>

no, i dont mean on mouse moving up and down… i mean when you get closer to the movie clip, it gets bigger… and when you get farther it gets smaller… as opposed to as it is now…

sorry for the confusion…

---

<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:** [October 5, 2002, 8:23pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/15 "2002-10-05T20:23:26Z")

</div>

Well you would need the mouse position to be able to do that right?

Test it out. My code works. All you have to do is add if statements to keep it from shrinking too small and getting to big and voila.

---

<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:** [October 5, 2002, 11:57pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/16 "2002-10-05T23:57:26Z")

</div>

Well, you’d need to get the distance, like before, but this time the scale is opposite to the distance:

```auto
var dx=_x-_root._xmouse;
var dy==_y-_root._ymouse;
var distance=dx*dx+dy*dy;
_xscale=_yscale=50/(distance+20 );

```

You’ll have to mess with the numbers 50 and 20 to get the effect you want.

Basically, I added 20 because if you don’t do that and distance=0, then scale=infinity, which is, hue… not good.

pom 😏

---

<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:** [October 6, 2002, 12:33am UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/17 "2002-10-06T00:33:13Z")

</div>

:q: umm that doesnt work…

when i divide by the distance… my mc just disappears…

---

<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:** [October 6, 2002, 1:55am UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/18 "2002-10-06T01:55:10Z")

</div>

Ah screw it…lol.

[http://www.flashkit.com/tutorials/Actionscripting/Expert/Building-Morten\_B-529/index.php](http://www.flashkit.com/tutorials/Actionscripting/Expert/Building-Morten_B-529/index.php)

THere, that is like what you want 😛 (yes I can be lazy sometimes too…well actually a lot)

PS: That tutorial has some strong coding in it so beware:)

---

<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:** [October 6, 2002, 7:51am UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/19 "2002-10-06T07:51:43Z")

</div>

Joshua Davis’ tsunami… Now this may be a bit complicated compared to what we’re trying to do here 😛

```auto
gridy=30;
gridx=30;
num=0;
mr._visible=0;
for (var i=0;i < 10;i++)
{
	for (var j=0;j < 10;j++)
	{
		mr.duplicateMovieClip("mr"+num,num);
		mc=this["mr"+num];
		mc._y=gridx*i+30;
		mc._x=gridy*j+30;
		mc.i=i;
		stupid = Math.round( Math.random()*0xFFFFFF );
		mybad = new color (_root.mc);
		mybad.setRGB(stupid);
		mc.onEnterFrame=function()
		{
			var dx=this._x-_root._xmouse;
			var dy=this._y-_root._ymouse;
			var distance=Math.sqrt(dx*dx+dy*dy);
			this._xscale=this._yscale=5000/(distance+20 );
			this.swapDepths(Math.round(this._xscale));
		}
		num++;
	}
}

```

The problem was that 50 wasn’t nearly enough to see anything. Hence the 5000 and the square root.

pom 😏

---

<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:** [October 6, 2002, 9:13pm UTC](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342/20 "2002-10-06T21:13:16Z")

</div>

thanks, thats great… i appreciate it… and ya that tsunami thingy was a little out of my league… for now anyway _evil laugh_… you will see… i am going to be the best flasher ever!.. (probably not though)… haha but thanks again…

[Next page](https://forum.kirupa.com/t/what-can-i-do-with-a-gird/6342.md?page=2)
