# What can I do with a gird?

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=gridxi+30;
mc._x=gridy
j+30;
stupid = Math.round( Math.random()*0xFFFFFF );
num++;
}
}

I’ll post something after the contest

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

``````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 );
mc.onEnterFrame=function()
{
this._xscale=this._yscale=50*(1+Math.sin(this.a+=.2))+10;
}
num++;
}
}
``````

pom :asian:

Or

``````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 );
mc.onEnterFrame=function()
{
this._xscale=this._yscale=50*(1+Math.sin(this.a+=.2+this._num/100 ))+10;
}
num++;
}
}
``````

pom :asian:

Hmm…

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

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

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

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?

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

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

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

``````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 dxdx+dydy, but this will work the same.

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

pom

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

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…

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

Something like this…

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

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…

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.

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

``````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

:q: umm that doesnt work…

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

Ah screw it…lol.

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

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

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

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…