Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
how to assign property that indicate target to movieclip in actionscript 2.0 and 3.0
Copy link to clipboard
Copied
it's the same in as2 and as3:
yourmovieclip.target=whatever;
Copy link to clipboard
Copied
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;
}
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;
}
}
Copy link to clipboard
Copied
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;
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now