10 Replies Latest reply on Jan 10, 2010 8:01 AM by NeronBurningRome

    Multiple roll over/out + attachMC = wrong coordinates of attached mc

    NeronBurningRome Level 1

      First the code:

       

      att = function (prev,nex,coox,alf) {
          attachMovie (nex, nex, _root.getNextHighestDepth());
          nex=eval(nex);
          nex._x = coox;
          nex._y = 160;
          prev._alpha = alf;

      }
      att(LetP,"LetP",80,100);

      LetP.onRollOver=function () {
          att(LetP, "LetPi", 80, 0);
      }

      LetP.onRollOut=function () {
          att (0,"LetPj",80,0);
          removeMovieClip ("LetPi");

          setTimeout(remPj, 10000);

      }

      remPj=function() {
          removeMovieClip ("LetPj");
          LetP._alpha = 100;
          };

       

      When I set mouse over first MC ("LetP") it starts second MC ("LetPi"). When I remove mouse from this area, LetPi is replaced with LetPj, which disappear after a while revealing LetP.

      Problem starts when I do this:

      mouse over the mc, then mouse out, then over again, and then out

      - result of this operation is that the LetPj appears where it should (that is x=80 and y=160), but it also appears in upper - left corner of the screen (x=0 and y=about 10,sometimes less).

      And untill the additional mc (the one at x=0) disappear the main mcs (those at x=80) act chaotically on roll over/out events.

      Is there a reason why it acts like this?

        • 1. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
          kglad Adobe Community Professional & MVP

          that code's not logical.

           

          what are you trying to do?

          • 2. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
            NeronBurningRome Level 1

            What do you mean 'not logical' ? It works...partly Ok, seriously - I'm trying to put (1st) mc on stage, then, on rollOver event set alpha of 1st mc to 0 and put another mc (2nd) in the same place, then on rollOut event put another mc(3rd) on the same place removing the 2nd one, and then, after a while remove the final mc(3rd) and restore 100% of alpha value of the 1st mc.

            Final effect of animation is a sign where every letter is a separate mc, and changes on roll over/out events. The "LetP" is just Letter P. I got other letters working with the same mechanism. I didn't want to write simmilar code for every letter so I created a function (called 'att'), which should take care of every letter.

            Maybe it would be easier to understand what I'm trying to do if I show my previous code without this function, where every letter had it separate code:

             

            attachMovie ("LetP", "LetP", _root.getNextHighestDepth());
                LetP._x = 80;
                LetP._y = 160;

             

            LetP.onRollOver=function () {
                attachMovie ("LetPi", "LetPi", _root.getNextHighestDepth());
                LetPi = eval ("LetPi")
                LetPi._x = 80;
                LetPi._y = 160;
                LetP._alpha = 0;
                }
               
            LetP.onRollOut=function () {
                removeMovieClip ("LetPi");
                attachMovie ("LetPj", "LetPj", _root.getNextHighestDepth());
                LetPj = eval ("LetPj");
                LetPj._x = 80;
                LetPj._y = 160;
                remPj=function() {
                    removeMovieClip ("LetPj");
                    LetP._alpha = 100;
                };
                setTimeout(remPj, 10000);
               
            }

            • 3. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
              kglad Adobe Community Professional & MVP

              "I'm trying to put (1st) mc on stage, then, on rollOver event set alpha of 1st mc to 0 and put another mc (2nd) in the same place..."

               

              if the 2nd movieclip is placed over the 1st (ie, the mouse will be over the 2nd movieclip), that will trigger a rollout of the first movieclip.  is that what you want?

              • 4. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
                NeronBurningRome Level 1

                "if the 2nd movieclip is placed over the 1st (ie, the mouse will be over the 2nd movieclip), that will trigger a rollout of the first movieclip. "

                 

                Are you sure it works that way? Coz I was testing it with 'trace' command and it seems to me that if the 1st mc is still on the stage (but hidden with alpha=0) and mouse is over the 1st and the 2nd mc, the rollOut event doesn't trigger. Example below returns "1" when mouse is over mc and "2" when mouse is rolled out.

                If it works as you say then I should get "1" and "2" returned when mouse is over mc, but it returns only "1".

                Am I thinking straight here?

                 

                 

                    attachMovie ("LetP", "LetP", _root.getNextHighestDepth());

                    LetP._x = 80;

                    LetP._y = 160;

                 

                    LetP.onRollOver=function () {

                    attachMovie ("LetPi", "LetPi", _root.getNextHighestDepth());

                    LetPi = eval ("LetPi");

                 

                    LetPi._x = 80;

                    LetPi._y = 160;

                 

                    LetP._alpha = 0;

                    trace("1");

                 

                    }

                 

                    LetP.onRollOut=function () {

                    removeMovieClip ("LetPi");

                    trace("2");

                    attachMovie ("LetPj", "LetPj", _root.getNextHighestDepth());

                    LetPj = eval ("LetPj");

                    LetPj._x = 80;

                    LetPj._y = 160;

                    remPj=function() {

                         removeMovieClip ("LetPj");

                        LetP._alpha = 100;

                    };

                    setTimeout(remPj, 10000);

                        removeMovieClip ("LetH");

                     }

                • 5. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
                  kglad Adobe Community Professional & MVP

                  you're correct.  that doesn't trigger a rollout.

                   

                  so, describe the letter effect you want to achieve.

                  • 6. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
                    NeronBurningRome Level 1

                    The effect is that there is a letter on a stage (e.i. "LetP"). When mouse goes over the letter it turns invisible (LetP._alpha=0, i make it invisible instead of removing it becouse onRollOut on LetP must be still active), and another letter ("LetPi") appears on the stage. When mouse rolls out of the letters the LetPi disappears and another letter ("LetPj") appears in the same place. The LetPj sits there for a while and then is removed from stage, at this time original letter ("LetP") turns visible.

                     

                    Everything works as I wrote, just there is a problem when I go over and out few times - then the LetPj appears where it should, but also in the upper left corner of stage. And it shouldn't appear there.

                     

                    I wonder has that something to do with depths (they're mixed up or something) or is there other reason.

                     

                    Thanks for your involvement kglad. If you have any idea what's wrong please let me know.

                    • 7. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
                      kglad Adobe Community Professional & MVP

                      that doesn't sound very useful.  are you only going to use 3 letter "words"?

                      • 8. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
                        NeronBurningRome Level 1

                        No

                         

                        The example I geve was just for one letter, it was letter "P". That's why every mc in code I've written above has the same coordinates (x,y). I got other letters, every one of them works with the same mechanism as "P". But other letters have different coordinates. I want every letter to animate independently.

                        Every letter has 3 versions. For "P" it is "LetP", "LetPi" and "LetPj".

                        For example letter "R" has instances of "LetR", "LetRi" and "LetRj". Letter "O" has instances of "LetO", "LetOi" and "LetOj". And so on....with more letters.

                         

                        I gave an example just for letter "P" so I'd know what to do with other letters

                         

                        My first post in this thread was a function, which was supposed to work for all the letters. And it might've been not very understandable function (I have sometimes trouble with figuring it out  ) But it works as I intended to. Code in my second post is easier to understand, but it has the same effect as code in the first post.

                         

                        Both versions of this code (my fist post, and my second post) works simmilar. But both of them have simmilar 'side effects' - instance of "LetPj" appears at the upper left corner of stege. And this side effect was not in my intentions

                         

                        I was interested in the reason why this instance of "LetPj" (or "LetRj" or "LetOj"...and so on) appears where it shouldn't be.

                         

                        Is that the explanation you were hoping for?

                        • 9. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
                          kglad Adobe Community Professional & MVP

                          don't change the code below the dotted line.  just call letterF() passing the letter (eg, "P") and the x and y coordinates.  for example:

                           

                          letterF("P",80,160);

                           

                          -----------------------------------------------

                          var tl:MovieClip = this;

                           

                          function letterF(S:String,x:Number,y:Number){
                              var mc:MovieClip = tl.attachMovie("Let"+S,"Let"+S,tl.getNextHighestDepth());
                              mc._x = x;
                              mc._y = y;
                              mc.S = S;
                              mc.onRollOver = function(){
                                  this._alpha = 0;
                                  var mc1:MovieClip = tl.attachMovie("Let"+this.S+"i","Let"+this.S+"i",tl.getNextHighestDepth());
                                  mc1._x = this._x;
                                  mc1._y = this._y;
                                  this.mc1 = mc1;
                              }
                              mc.onRollOut = function(){
                                  this.mc1.removeMovieClip();
                                  var mc2:MovieClip = tl.attachMovie("Let"+this.S+"j","Let"+this.S+"j",tl.getNextHighestDepth());
                                  mc2._x = this._x;
                                  mc2._y = this._y;
                                  setTimeout(resetF,10000,mc2,this);
                              }
                          }

                           

                          function resetF(mc2:MovieClip,mc:MovieClip){
                              mc2.removeMovieClip();
                              mc._alpha = 100;
                          }

                          • 10. Re: Multiple roll over/out + attachMC = wrong coordinates of attached mc
                            NeronBurningRome Level 1

                            Thnaks, it works.

                            So basically what was wrong with my code? Was it that onRollOver an onRollOut events should be inside tha main function?

                             

                            And I found something strange, one of the letters ("LetO" instance of letter O) disappear after clicking on a thumbnail in photo gallery. It's strange that only one letter disappears and rest of them stay.

                            Code in photo gallery, which makes the letter disappear is:

                             

                                thumb_mc.onRelease = function() {
                                    var j = this.ivar;
                                    full_mc = _parent.createEmptyMovieClip("full"+j, this.getNextHighestDepth());
                                    full_mc.createEmptyMovieClip("targetFULL", this.getNextHighestDepth());
                                    loader2.loadClip("full_images/image"+j+".jpg", full_mc.targetFULL);
                                };

                             

                            preloader2.onLoadProgress = function (target,bytesLoaded,bytesTotal) {
                                var procent = Math.round(bytesLoaded/bytesTotal * 100);
                                attachMovie("bar","bar",100);
                                bar._height = 10;
                                bar._x = procent*8;
                                bar._y = 550;
                            }

                             

                             

                             

                            I'm not sure whether the onRelease or onLoadProgress makes the letter disappear, but I'm sure the letter disappears before onLoadInit starts. And I don't see anything in code above that could make the letter O disappear.

                            Any ideas?