Skip to main content
Inspiring
February 11, 2022
Answered

Limit movement of symbol along axis

  • February 11, 2022
  • 2 replies
  • 187 views

I have a graphic symbol being moved along the X axis programmatically via button press.

 

How can I limit the movement of that symbol to a certain point on the stage, e.g. along X axis?

 

I assume I can get the position of the symbol like:

 

var leftFrame_X = this.LeftFrame.x;

 

Is that position different from the x position shown in properties?

 

How would I test for that position and stop the symbol from moving further in that direction?

 

Like this?

 

function updateLF_Move_Right(){

	if(leftFrame_X != leftFrame_X){
root.LeftFrame.x+=1
	} else {
root.LeftFrame.x+=0
}

 

This is the code I currently have:

 

this.ButtonLeftFrameMoveRight.addEventListener("mousedown", LF_MoveRight_Down.bind(this));
this.ButtonLeftFrameMoveRight.addEventListener("pressup", LF_MoveRight_Up.bind(this));

var frameLeft = this;

function LF_MoveRight_Down() {
    
createjs.Ticker.addEventListener("tick",updateLF_Move_Right);
    
}

function LF_MoveRight_Up() {

createjs.Ticker.removeEventListener("tick",updateLF_Move_Right);

}

function updateLF_Move_Right(){

frameLeft.LeftFrame.x+=1

}

 

 

    This topic has been closed for replies.
    Correct answer FlatChat

    Sorted:

     

    function updateLF_Move_Right(){
    	if(root.LeftFrame.x <= 597.3){	
    root.LeftFrame.x+=1;
    	}
    }
    
    function updateLF_Move_Left(){
    if(root.LeftFrame.x >= 508.3){	
    root.LeftFrame.x-=1
    }	
    }

    2 replies

    FlatChatAuthorCorrect answer
    Inspiring
    February 14, 2022

    Sorted:

     

    function updateLF_Move_Right(){
    	if(root.LeftFrame.x <= 597.3){	
    root.LeftFrame.x+=1;
    	}
    }
    
    function updateLF_Move_Left(){
    if(root.LeftFrame.x >= 508.3){	
    root.LeftFrame.x-=1
    }	
    }
    FlatChatAuthor
    Inspiring
    February 11, 2022

    That shoul read:

     

    if(leftFrame_X != some pos X){