6 Replies Latest reply on Sep 8, 2009 11:21 AM by marcelozepgames

    [as1, as2] Attaching Objects

    marcelozepgames

      Hello.

      I would like to know, how to attach two objects (movieclips), with different width and height properties into the stage, with random positions,

      without visual colliding.

      Thank you.

       

      marcelozep.

        • 1. Re: [as1, as2] Attaching Objects
          kglad Adobe Community Professional & MVP

          are these movieclips that already are on-stage or are they library movieclips that have a linkage id or something else?

          • 2. Re: [as1, as2] Attaching Objects
            marcelozepgames Level 1

            They are on library, each one has an id.

            • 3. Re: [as1, as2] Attaching Objects
              kglad Adobe Community Professional & MVP

              if one movieclip has linkage id="id1" and the other = "id2":

               

              var mc1:MovieClip=this.attachMovie("id1","mc1",1);

              mc1._x=Math.round((Stage.width-mc1._width)*Math.random());  // assuming left-edge reg pt

              mc1._y=Math.round((Stage.height-mc1._height)*Math.random());  // assuming top-edge reg pt

               

              // same code with a 2 instead of 1 will work for your 2nd movieclip

              • 4. Re: [as1, as2] Attaching Objects
                marcelozepgames Level 1

                The objects are left registration point.

                But, the objects (movieclips), must be attached and can´t collide visually.

                So, it must calculate, wich widht or height is bigger (I think), and then

                attach on stage.

                When they are on stage, they must be in a position that they aren´t colliding visually.

                 

                marcelozep

                • 5. Re: [as1, as2] Attaching Objects
                  kglad Adobe Community Professional & MVP

                  hopefully they're both significantly less than Stage.width/2 x Stage.height/2:

                   

                   

                  var mc1:MovieClip=this.attachMovie("id1","mc1",1);

                  placeMCF(mc1);

                   

                  function placeMCF(mc:MovieClip){

                  mc._x=Math.round((Stage.width-mc._width)*Math.random());  // assuming left-edge reg pt

                  mc._y=Math.round((Stage.height-mc._height)*Math.random());  // assuming top-edge reg pt

                  }

                   

                   

                  var mc2:MovieClip=this.attachMovie("id2","mc2",2);

                  var raceConditionCheck:Number=0;

                  placeMCWithoutContactF(mc2,mc1);

                   

                   

                  function placeMCWithoutContactF(mc:MovieClip,mc1:MovieClip){

                  placeMCF(mc);

                  raceConditionCheck++;

                  if(raceConditionCheck<100){

                  if(mc.hitTest(mc1)){

                  placeMCWithoutContact(mc);

                  }

                  } else {

                  placeMCF(mc1);

                  // and you should add another racecondition check here.

                  }

                  }

                  • 6. Re: [as1, as2] Attaching Objects
                    marcelozepgames Level 1
                    I´ll try again.
                    I need to attach, two movieclips, into the stage.
                    These two movieclips, are top-left registration point.
                    These two movieclips, has in each one, another movieclip, wich are center registration point.
                    This movieclip, that has, center, registration point, when on the stage, will rotate.
                    So, how to attach the two main movieclips, that has top-left registration point, in a way, that they won´t collide visualy while their inside movieclips are rotating.

                     

                    What is important here is:

                     

                    It is the same draw for the main movieclip and for the holder movieclip of the draw.
                    But each main movieclip, I mean, different main movieclips has holders movieclips with different draws.
                    In other words, there are the movieclip that holds the draw ( the one that rotates), and the main movieclip that holds the movieclip that holds the draw.
                    When the main movieclip goes on stage, the movieclip that holds the draw, rotates.
                    So this is why, I think it is important to calculate what is the bigger part of the draw, its height, or, its width.

                     

                    While they are rotating, they can´t collide visually.

                     

                    Thank you.