Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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;




  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    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.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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;
    }




  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •