Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to move an object to specific area

New Here ,
Jan 06, 2016 Jan 06, 2016

I want to move two objects in two areas but one area is specified for one object but not for the other. When that object is moved to the second area not specified for that then that object should come back to its original position.

TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 07, 2016 Jan 07, 2016

make both objects movieclips and assign a property to each that indicates its target.

use a hitTestObject to determine if each is dropped on its target.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 07, 2016 Jan 07, 2016

how to assign property that indicate target to movieclip in actionscript 2.0 and 3.0

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 07, 2016 Jan 07, 2016

it's the same in as2 and as3:

yourmovieclip.target=whatever;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 21, 2016 Jan 21, 2016

I am trying this code and it is working perfectly:

chk.onPress=function(){

  startDrag(this);

}

chk.onRelease=function(){

  stopDrag();

  checkTarget(this);

}

chk.onReleaseOutside=function(){

  stopDrag();

  checkTarget(this);

}

function checkTarget(drag){

  if(eval(chk._droptarget)==squ4)

  {

  chk._x=770;

  chk._y=330;

  }else{

  chk._x=455;

  chk._y=550;

    }

}javascript:;

But i have to add another object as below but as soon as i do this, the above stops working.

bird.onPress=function(){

  startDrag(this);

}

bird.onRelease=function(){

  stopDrag();

  checkTarget(this);

}

bird.onReleaseOutside=function(){

  stopDrag();

  checkTarget(this);

}

function checkTarget(drag){

  if(eval(bird._droptarget)==squ4)

  {

  bird._x=770;

  bird._y=330;

  }else{

  bird._x=870;

  bird._y=555;

    }

}

Picture1.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2016 Jan 21, 2016

use:

var birdA:Array=[bird1,bird2,bird3,bird4];

for(var i:Number=0;i<birdA.length;i++){

birdA[.target=squ4;

birdA.onPress=startDragF;

birdA.onRelease=birdA.onReleaseOutside=stopDragF;

birdA.startX=birdA._x;

birdA.startY=birdA._y;

}

function startDragF():Void{

this.startDrag();

}

function stopDragF():Void{

this.stopDrag();

if(eval(this._dropTarget)==this.target){

this._x = this.target._x;

this._y = this.target._y;

} else {

this._x = this.startX;

this._y = this.startY;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 21, 2016 Jan 21, 2016

how to code the rest?

I mean chk was for chicken which we have to move squ4. Now birds also have to move to squ4.

but bears and pencils have to move to squr4.

when one coding is done, its fine, but when other is done, first just vanishes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2016 Jan 21, 2016
LATEST

use:

var birdA:Array=[bird1,bird2,bird3,bird4];

var chickA:Array=[chk1,chk2,chk3,chk4];

var bearA:Array=[bear1,bear2,bear3];

var pencilA:Array=[pencil1,pencil2,pencil3];

////

handlerF(birdA.squ4);

handlerF(chickA.squ4);

handlerF(bearA.squr4);

handlerF(pencilA.squr4);

function handlerF(a:Array,target:MovieClip):Void{

for(var i:Number=0;i<a.length;i++){

a[.target=target;

a.onPress=startDragF;

a.onRelease=a.onReleaseOutside=stopDragF;

a.startX=a._x;

a.startY=a._y;

}

}

function startDragF():Void{

this.startDrag();

}

function stopDragF():Void{

this.stopDrag();

if(eval(this._dropTarget)==this.target){

this._x = this.target._x;

this._y = this.target._y;

} else {

this._x = this.startX;

this._y = this.startY;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines