5 Replies Latest reply on Dec 21, 2012 7:19 AM by kglad

    Drag and drop wont work inside parent movieclip?

    LukeElChul Level 1

      I have a drag function in the timeline

       

       

      var Spells:Array = new Array(spellBook.Spell1, spellBook.Spell2, spellBook.Spell3, spellBook.Spell4, spellBook.Spell5, spellBook.Spell6, spellBook.Spell7, spellBook.Spell8, spellBook.Spell9);

       

      var SpellIdentity:String = "";

      var Dragging:Boolean = false;

       

       

      for (i=0; i<Spells.length; i++) {

                _root.Spells[i].onPress = function() {

                                    trace("drag")

                          if (Dragging == false) {

                                    Dragging = true;

                                    originx = this._x;

                                    originy = this._y;

                                    this.startDrag("");

                          }

      }

      }

       

      I have this code lets me drag 9 spells. But theres a problam, I have the 9 spells MC's in a MovieClip Called spellbook which has 2 frames the first one being blank and the secound with the spells on and when I open the spellbook (goto frame 2) the spells wont drag, if I get the spells out the spellbook and just put them on the scene they drag fine.

       

      So bacicly the spells wont drag when they are a child of another movieclip. Any Ideas???

        • 1. Re: Drag and drop wont work inside parent movieclip?
          kglad Adobe Community Professional & MVP

          from your description, there's no movieclip spellBook.Spell1, for example, when your code executes because spellBook has none of those movieclips on its first frame and spellBook is on its first frame when that code executes.

           

          to remedy, put your spells on frame 1, too.  you can assign their _alpha to be zero or their _visible property to be false on frame 1 and then 100 or true on frame 2.

           

          you'll also need to direct spellBook to frame 2 for those spells to be visible when you're dragging (if that's what you want).

          1 person found this helpful
          • 2. Re: Drag and drop wont work inside parent movieclip?
            LukeElChul Level 1

            Thanks for the reply

             

            How can I direct spellbook to frame 2 as you said, because Ive tryed making it ._alpha = 0 but it causes interface gliches in the rpg I am making. so I need frame 1 to be empty and frame 2 to have the spells in. How could I Do this?

             

            Thankx for helping

            • 3. Re: Drag and drop wont work inside parent movieclip?
              kglad Adobe Community Professional & MVP

              try:

               

               

              spellBook.gotoAndStop(2);

              var Spells:Array;

              this.onEnterFrame=spellsArrayF;

               

              function spellsArrayF(){

              Spells = new Array(spellBook.Spell1, spellBook.Spell2, spellBook.Spell3, spellBook.Spell4, spellBook.Spell5, spellBook.Spell6, spellBook.Spell7, spellBook.Spell8, spellBook.Spell9);

              delete this.onEnterFrame;

              dragF();

              }

               

               

              var SpellIdentity:String = "";

              var Dragging:Boolean = false;

               

              function dragF(){

              for (i=0; i<Spells.length; i++) {

                        _root.Spells[i].onPress = function() {

                                            trace("drag")

                                  if (Dragging == false) {

                                            Dragging = true;

                                            originx = this._x;

                                            originy = this._y;

                                            this.startDrag("");

                                  }

              }

              // you'll need a stopDrag, too:

              _root.Spells[i].onRelease=function(){

              this.stopDrag();

              }

              }

              }