Skip to main content
Participant
July 29, 2021
Answered

drag drop objects in different frames

  • July 29, 2021
  • 1 reply
  • 252 views

Hi everyone,

 

Having trouble with my Fla and its drag and drop objects not appearing in their root position when moving back and fourth on the timeline.

I managed to add an "add.Eventlistener" to a restart button to place objects in their original position within the frame but I'd like this to be automatic when going back to a previous frame.

Ideally (!) my prevButton symbol would need to have BOTH "go to previous frame" and "start with objects in their root position". Both codes are below...

 

fla here:

http://www.violinopedia.com/template_290721.fla

 

Any hint ?

 

Thanks !

 

this.navigationLoop = true; // set to true or false to enable or disable loop when the current position is the first or the last frame
if (!this.hasStarted)
{
     this.prevFrame = function(e)
     {
          if (this.navigationLoop && this.currentFrame == 0)
              this.gotoAndStop(this.timeline.duration - 1);
          else
              this.gotoAndStop(this.currentFrame - 1);
     };
this.prevButton.on("click", this.prevFrame, this);
     this.stop();
     this.hasStarted = true;
 
     this.nextFrame = function(e)
     {
         if (!this.navigationLoop && this.currentFrame == this.timeline.duration - 1)
               return;
         this.gotoAndStop(this.currentFrame + 1);
     };
     this.nextButton.on("click", this.nextFrame, this);
     this.stop();
     this.hasStarted = true;
}
 
 
this.restartButton.addEventListener("click", onClickrestartButton);
var root=this;
var arr=[];
for(var i=0; i<root.numChildren; i++){
arr.push([root.getChildAt(i).id, root.getChildAt(i).x, root.getChildAt(i).y]);
}
window.arrElement=arr;
 
function onClickrestartButton() {
for(var i=0; i<window.arrElement.length; i++){
var element = window.arrElement[i];
if(root.getChildAt(i).id==element[0]){
root.getChildAt(i).x = element[1];
root.getChildAt(i).y = element[2];
}
}
}
    This topic has been closed for replies.
    Correct answer kglad

    when your frame is entered use:

     

    var alreadyExecuted;

    if(!alreadyExecuted){

    alreadyExected=true;

    /* loop through all the object's whose position you want to restore and store their positions */

    // for example, if that's movieclips this.mc0, this.mc1,..,this.mc55, use:

    for(var i=0;i<56;i++){

    this["mc"+i].initX = this["mc"+i].x;

    this["mc"+i].initY = this["mc"+i].y;

    }

    } else {

    // on returns, reset their positions

    for(var i=0;i<56;i++){

    this["mc"+i].x = this["mc"+i].initX;

    this["mc"+i].y = this["mc"+i].initY;

    }

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    July 29, 2021

    when your frame is entered use:

     

    var alreadyExecuted;

    if(!alreadyExecuted){

    alreadyExected=true;

    /* loop through all the object's whose position you want to restore and store their positions */

    // for example, if that's movieclips this.mc0, this.mc1,..,this.mc55, use:

    for(var i=0;i<56;i++){

    this["mc"+i].initX = this["mc"+i].x;

    this["mc"+i].initY = this["mc"+i].y;

    }

    } else {

    // on returns, reset their positions

    for(var i=0;i<56;i++){

    this["mc"+i].x = this["mc"+i].initX;

    this["mc"+i].y = this["mc"+i].initY;

    }