Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-17-2009, 10:37 AM   PM User | #1
gencoglu
New Coder

 
Join Date: Jun 2007
Posts: 38
Thanks: 6
Thanked 0 Times in 0 Posts
gencoglu is an unknown quantity at this point
positioning mcs on the stage

Hi,
I have 20 rectangle shaped movie clips.m1,m2,m3,...m20,I want to display only 5 of them randomly.and the NCs should be unique(no dublications) need to change their _y position randomly everytime clciking a button..but there must be 10px space between them... so how do I modify the code to do it ?
thanks
PHP Code:
 myArray = new Array(m1m2m3m4m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15,m16,m17,m18,m19,m20);

for (
i=0i<=myArray.lengthi++) {
_root["m"+i]._x=400;
_root["m"+i]._y=Math.floor(Math.random()*300)+20;



gencoglu is offline   Reply With Quote
Old 01-17-2009, 11:23 AM   PM User | #2
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
That would require a little more work. I don't have the time to actually make the calculations or functions, but here is an idea of the logic.

You would need to first change your for loop to only display 5, right now it places all 20.

You need to make a function that will take the current position of an element, and check if it is within 10px of any other. If not then it places the element, if it does want to place something too close, then you need to have it rerun the function to get a new random place.
__________________
jeremy - gnomeontherun
Educated questions often get educated answers, and simple questions often get simple answers.
gnomeontherun is offline   Reply With Quote
Old 01-17-2009, 07:18 PM   PM User | #3
gencoglu
New Coder

 
Join Date: Jun 2007
Posts: 38
Thanks: 6
Thanked 0 Times in 0 Posts
gencoglu is an unknown quantity at this point
Hi,
Now I can craete a random movement for the MCs
but there is always a space in between which is more than 20px...any idea ?

PHP Code:
on(Press){
6;  
ary = [];
for (var 
0n; ++iary[i] = i;
ary.sort( function() { return random(2)? :-1; });

var 
bir = new Array(m1m2m3m4m5);
var 
hedef = new Array(h1h2h3h4h5);
var 
say=0;
for (
z=0z<=bir.lengthz++) {
    
_root["m"+z]._x=500;
    
_root["m"+z]._y=(ary[z]*50)+40;
    
_root.kutu.text=ary;
}


gencoglu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:23 AM.


Advertisement
Log in to turn off these ads.