Copy link to clipboard
Copied
Its a mobile game. Adobe flash cs6
Leo Angelo Laude wrote:
but i have many objects to be drag. it is possible to have one function?
yes, that's why i posted, '(but you should actually be using one function for all your startDrag() and another function for all your stopDrag() methods so you don't have to write the same code repeatedly.)'
you should be using something like:
var draggedObject:MovieClip;
var draggableObjectsA:Array=[...];
for(var i:int=0;i<draggableObjectsA.length;i++){
draggableObjectsA.addEventListener(MouseEvent.MOU
...Copy link to clipboard
Copied
with your startDrag(), use:
whatever.parent.addChild(whatever); // where whatever is the object that's starting to be dragged.
with stopDrag(), use:
whatever.parent.addChildAt(whatever,0); // to add at bottom of display list
Copy link to clipboard
Copied
function dragDressKatipon1(m:MouseEvent){
mcDressKatipon.startDrag(true); | |
datingX=458; | |
datingY=300; | |
} |
function undragDressKatipon1(m:MouseEvent){
mcDressKatipon.stopDrag(); | ||||
if (mcFigure.hitTestObject(mcDressKatipon)&& rightAns == 1){ | ||||
trace("tama"); | ||||
scoreDressCode++; | ||||
txtDressCodeScore.text = "" + scoreDressCode; | ||||
//txtDressCodeScore2.text = "" + scoreDressCode; | ||||
DressCode(); | ||||
TweenLite.to(mcDressKatipon, 1, { x:1082.40, y: 304.15}); | ||||
TweenLite.to(mcDressKatipon, 1, {x:datingX, y:datingY, delay:2, ease:Elastic.easeOut}); | ||||
TweenLite.to(mccorrectDressCode, 1, {rotation: 360, x:975.9, y: 6.55, ease:Elastic.easeInOut}); | ||||
TweenLite.to(mccorrectDressCode, 2, {rotation: 360, delay:2, x:-975.9, y: -6.55, ease:Elastic.easeInOut}); | ||||
} | ||||
else if(mcFigure.hitTestObject(mcDressKatipon) && rightAns != 1 ){ | ||||
trace("mali"); | ||||
wrong_DressCode++; | ||||
TweenLite.to(mcDressKatipon, 1, {x:datingX, y:datingY, ease:Elastic.easeOut}); | ||||
if(wrong_DressCode == 1) | ||||
TweenLite.to(mcFirstLife, 1, {scaleX:0, scaleY:0}); | ||||
} | ||||
if(wrong_DressCode > 1) | ||||
{ | ||||
TweenLite.to(mcThirdLife, 1, {scaleX:0, scaleY:0}); | ||||
} | ||||
if(wrong_DressCode > 2) | ||||
{ | ||||
TweenLite.to(mcThirdLife, 1, {scaleX:0, scaleY:0}); | ||||
TweenLite.to(GameOverDressCode, 1, {x:641.15, y:361.1}); | ||||
TweenLite.to(txtScoreDressCode2, 1, {delay:.5, x:588, y:354.15}); | ||||
TweenLite.to(mcPlayDressCode, 1, {delay:1, x:652.3, y:612.9}); | ||||
} | ||||
} |
Copy link to clipboard
Copied
Leo Angelo Laude wrote:
function dragDressKatipon1(m:MouseEvent){
mcDressKatipon.startDrag(true); mcDressKatipon.parent.addChild(mcDressKatipon);
datingX=458;
datingY=300; } function undragDressKatipon1(m:MouseEvent){
mcDressKatipon.stopDrag();
mcDressKatipon.parent.addChildAt(mcDressKatipon,0);
if (mcFigure.hitTestObject(mcDressKatipon)&& rightAns == 1){ trace("tama"); scoreDressCode++; txtDressCodeScore.text = "" + scoreDressCode; //txtDressCodeScore2.text = "" + scoreDressCode; DressCode(); TweenLite.to(mcDressKatipon, 1, { x:1082.40, y: 304.15}); TweenLite.to(mcDressKatipon, 1, {x:datingX, y:datingY, delay:2, ease:Elastic.easeOut}); TweenLite.to(mccorrectDressCode, 1, {rotation: 360, x:975.9, y: 6.55, ease:Elastic.easeInOut}); TweenLite.to(mccorrectDressCode, 2, {rotation: 360, delay:2, x:-975.9, y: -6.55, ease:Elastic.easeInOut}); } else if(mcFigure.hitTestObject(mcDressKatipon) && rightAns != 1 ){ trace("mali"); wrong_DressCode++; TweenLite.to(mcDressKatipon, 1, {x:datingX, y:datingY, ease:Elastic.easeOut}); if(wrong_DressCode == 1) TweenLite.to(mcFirstLife, 1, {scaleX:0, scaleY:0}); } if(wrong_DressCode > 1) { TweenLite.to(mcThirdLife, 1, {scaleX:0, scaleY:0}); } if(wrong_DressCode > 2) { TweenLite.to(mcThirdLife, 1, {scaleX:0, scaleY:0}); TweenLite.to(GameOverDressCode, 1, {x:641.15, y:361.1}); TweenLite.to(txtScoreDressCode2, 1, {delay:.5, x:588, y:354.15}); TweenLite.to(mcPlayDressCode, 1, {delay:1, x:652.3, y:612.9}); } }
Copy link to clipboard
Copied
thanks but when i drag into mcFigure (the container) it goes at the back.
Copy link to clipboard
Copied
add the same code to mcFigure.
(but you should actually be using one function for all your startDrag() and another function for all your stopDrag() methods so you don't have to write the same code repeatedly.)
Copy link to clipboard
Copied
but i have many objects to be drag. it is possible to have one function?
Copy link to clipboard
Copied
Leo Angelo Laude wrote:
but i have many objects to be drag. it is possible to have one function?
yes, that's why i posted, '(but you should actually be using one function for all your startDrag() and another function for all your stopDrag() methods so you don't have to write the same code repeatedly.)'
you should be using something like:
var draggedObject:MovieClip;
var draggableObjectsA:Array=[...];
for(var i:int=0;i<draggableObjectsA.length;i++){
draggableObjectsA.addEventListener(MouseEvent.MOUSE_DOWN,startdragF);
draggableObjectsA.origIndex=draggableObjectsA.parent.getChildIndex(draggableObjectsA);
}
function startdragF(e:MouseEvent):void{
draggedObject=e.currentTarget;
draggedObject.startDrag();
draggedObject.parent.addChild(draggedObject);
stage.addEventListener(MouseEvent.MOUSE_UP,stopdragF);
}
function stopdragF(e:MouseEvent):void{
draggedObject.stopDrag();
draggedObject.parent.addChildAt(draggedObject.origIndex);
stage.removeEventListener(MouseEvent.MOUSE_UP,stopdragF);
}
Copy link to clipboard
Copied
if (mcFigure.hitTestObject(mcDressKatipon)&& rightAns == 1){
mcDressKatipon.parent.addChildAt(mcDressKatipon, 155);
trace("tama");
scoreDressCode++;
txtDressCodeScore.text = "" + scoreDressCode;
//txtDressCodeScore2.text = "" + scoreDressCode;
DressCode();
TweenLite.to(mcDressKatipon, 1, { x:1082.40, y: 304.15});
TweenLite.to(mcDressKatipon, 1, {delay:2, x:datingX, y:datingY, ease:Elastic.easeOut});
TweenLite.to(mccorrectDressCode, 1, {rotation: 360, x:975.9, y: 6.55, ease:Elastic.easeInOut});
TweenLite.to(mccorrectDressCode, 2, {delay:2, rotation: 360, x:-975.9, y: -6.55, ease:Elastic.easeInOut});
}
look at the bold line. i added. it works. but after dragging a the object and back again, the object goes in front
Copy link to clipboard
Copied
Leo Angelo Laude wrote:
if (mcFigure.hitTestObject(mcDressKatipon)&& rightAns == 1){
mcDressKatipon.parent.addChildAt(mcDressKatipon, 155);
that's not the code i suggested and almost certainly will cause a problem.
Copy link to clipboard
Copied
when i drag the dress into the human body its right. it goes in front. but after that i dress goes front also. let me send you the next picture
Copy link to clipboard
Copied
here the dress Katipun goes in front. It should the like bayani and kawal dress which is at the back
Copy link to clipboard
Copied
use the code in message 10.
Copy link to clipboard
Copied
i dont uderstand the code. sorry.
Copy link to clipboard
Copied
just add your objects to var draggableObjectsA:Array=[...];
and use the code instead of the drag and drop code you're currently using.
Copy link to clipboard
Copied
i make new file
it has error
draggedObject=e.currentTarget;
Copy link to clipboard
Copied
import flash.events.MouseEvent; | |
import flash.display.MovieClip; | |
import flash.display.DisplayObject; | |
import flash.events.EventDispatcher; | |
import flash.events.Event; |
var draggedObject:MovieClip;
var draggableObjectsA:Array=[mcBox];
for(var i:int=0;i<draggableObjectsA.length;i++){
draggableObjectsA.addEventListener(MouseEvent.MOUSE_DOWN,startdragF);
draggableObjectsA.origIndex=draggableObjectsA.parent.getChildIndex(draggableObjectsA );
}
function startdragF(e:MouseEvent){
draggedObject=e.currentTarget;
draggedObject.startDrag();
draggedObject.parent.addChild(draggedObject);
stage.addEventListener(MouseEvent.MOUSE_UP,stopdragF);
}
function stopdragF(e:MouseEvent){
draggedObject.stopDrag();
draggedObject.parent.addChildAt(draggedObject.origIndex);
stage.removeEventListener(MouseEvent.MOUSE_UP,stopdragF);
}
CHECK THIS. COPY AND PASTE
Copy link to clipboard
Copied
if the error is an implicit coercion error, use
draggedObject=MovieClip(e.currentTarget);
Copy link to clipboard
Copied
how about this?
draggedObject.parent.addChildAt(draggedObject.origIndex);
incorrect number of documents. Expected 2
Copy link to clipboard
Copied
use:
draggedObject.parent.addChildAt(draggedObject,draggedObject.origIndex);
Copy link to clipboard
Copied
thanks you so much. you helped me a lot
how about in not overlapping the falling objects?
(sorry for many questions)
Copy link to clipboard
Copied
check your other thread about that.
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Copy link to clipboard
Copied
how or where can I mark it as correct answers.
Sent from my iPhone
Copy link to clipboard
Copied
go to the forum using a full browser, How can I bring in front the objects in adobe flash when dragging and send it back.
and click correct answer:
and you may also be able to mark helpful answers by clicking actions:
Copy link to clipboard
Copied
i maeked the message 10. but ib 21 dont have a correct answer button
Find more inspiration, events, and resources on the new Adobe Community
Explore Now