import flash.events.MouseEvent;
stop();
btn1ileri.addEventListener(MouseEvent.CLICK, ileri1);
function ileri1(event:MouseEvent):void
{
nextFrame();
}
有3个目标dogrucevap1
,dogrucevap2
和dogrucevap3
。还有28个拼图。
目的是将拼图(cvp1,cvp2,..cvp28
)拖动到目标。
拼图碎片在粘贴到目标后不会碰撞,每个目标只有1个拼图块。因此,如果拼图相互碰撞,他们将返回到他们的第一个位置。
我无法将这些碎片归还原来的位置。
请检查returnfirstposition()
var puzzle:MovieClip=new MovieClip();
var puzzleparcalari:String;
var ilkX:int;
var ilkY:int;
for (var i:int=1; i<=28; i++)
{
puzzleparcalari = "cvp" + i;
puzzle = this[puzzleparcalari];//this["cvp" + i].buttonMode = true;
this["cvp" + i].addEventListener(MouseEvent.MOUSE_DOWN,surukle);
this["cvp" + i].addEventListener(MouseEvent.MOUSE_UP,birak);
}
function kontrol(e:Event) // checking recording first positions as ilkX and ilkY
{
this["cvp" + i].addEventListener(Event.ENTER_FRAME , kontrol);
ilkX = this["cvp" + i].x;
ilkY = this["cvp" + i].y;//this["cvp" + i].removeEventListener(Event.ENTER_FRAME , kontrol);
}
function surukle(e:MouseEvent) // starting drag and tracing x position
{
e.currentTarget.startDrag();
ilkX = e.currentTarget.x;
ilkY = e.currentTarget.y;//e.currentTarget.buttonMode = true;
trace(e.currentTarget.x);
}
var kutucuk:MovieClip=new MovieClip();
var kutucukismi:String;//d1.addEventListener(MouseEvent.MOUSE_DOWN,surukle);
function returnfirstposition() /creating return first position function
{
this.puzzle.x = ilkX;
this.puzzle.y = ilkY;
}
function birak(e:MouseEvent)
{
e.currentTarget.stopDrag();
for (var k:int=1; k<=3; k++)
{
kutucukismi = "dogrucevap" + k;
kutucuk = this[kutucukismi];
if (e.currentTarget.hitTestObject(this.kutucuk))
{
e.currentTarget.x = ilkX;
e.currentTarget.y = ilkY;
trace("kutucuk");
for (var i:int=1; i<=28; i++)
{
puzzleparcalari = "cvp" + i;
puzzle = this[puzzleparcalari];
if (e.currentTarget.hitTestObject(this.puzzle))
{
e.currentTarget.x = this.kutucuk.x;
e.currentTarget.y = this.kutucuk.y;
trace("this puzzle a değdi");
}
else
{
returnfirstposition();
}
}
}
}
}
答案 0 :(得分:0)
如果&#34; cvp&#34; +我是一个动画片段,你可以添加&#34; originalX&#34;和&#34; originalY&#34;比例并使用它们来返回动画片段:
//将此添加到您的第一个循环:
for (var i:int=1; i<=2; i++)
{
puzzleparcalari = "cvp" + i;
puzzle = this[puzzleparcalari];
this["cvp" + i].addEventListener(MouseEvent.MOUSE_DOWN,surukle);
this["cvp" + i].addEventListener(MouseEvent.MOUSE_UP,birak);
this["cvp" + i].originalX=this["cvp" + i].x;
this["cvp" + i].originalY=this["cvp" + i].y;
}
//and then in you drop function (e.currentTarget is the dropped piece):
if (e.currentTarget.hitTestObject(this.puzzle))
{
e.currentTarget.x = this.kutucuk.x;
e.currentTarget.y = this.kutucuk.y;
trace("this puzzle a değdi");
}
else
{
e.currentTarget.x = e.currentTarget.originalX;
e.currentTarget.y = e.currentTarget.originalY;
}