2013-10-15 63 views
0

我試圖做一個拖放遊戲,其中一個條件是當一個對象被放置到某個位置時,下一步應該出現。Actionscript 3.0對象位置來隱藏其他對象

我對編碼非常非常陌生,並且大部分都是盲人。我創造了這個代碼,但我不知道如果我寫它的權利,讓我的遊戲正常運行了

gamefacetemplate.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2); 

function fl_ClickToDrag_2(event:MouseEvent):void 
{ 
    gamefacetemplate.startDrag(); 
} 

gamefacetemplate.addEventListener(MouseEvent.MOUSE_MOVE, fl_ObjectPosition); 

function fl_ObjectPosition(event:MouseEvent):void 
{ 
    gamefacetemplate.x = 706.90; 
    gamefacetemplate.y = 311.90; 
} 

gamefacetemplate.addEventListener(MouseEvent.CLICK, fl_MoveToHide_6); 

function fl_MoveToHide_6(event:MouseEvent):void 
{ 
    instrustep2.visible = false; 
} 

stage.addEventListener(MouseEvent.CLICK, fl_ReleaseToDrop); 

function fl_ReleaseToDrop(event:MouseEvent):void 
{ 
    gamefacetemplate.stopDrag(); 
} 

{ 
gamefacetemplate.visible = false; 
} 

{ 
    gotoAndStop(5); 
} 

任何和所有幫助將不勝感激。

+0

第一,大括號之間的最後兩行不正確。看起來你可能想在那裏定義一個函數?其次,我沒有看到任何看起來像條件​​的東西。 – Ronnie

回答

0

我給你2個exemples,所以我只是刪除它,我不很瞭解的intrustep對象;)
下面的代碼只是用來將gamefacetemplate對象拖到一個位置(i增加利潤率的位置,它更靈活),如果拖動到正確的位置,則轉到第5幀,否則對象將返回到初始位置。因此,有兩種解決方案: 如果你想拖動到位置
激活下一步:

gamefacetemplate.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2); 

// maybe you want to keep te original position of the dragin object 
var originalPos:Point; 

function fl_ClickToDrag_2(event:MouseEvent):void 
{ 
    // keep original position 
    originalPos = new Point(gamefacetemplate.x, gamefacetemplate.y); 

    // start dragging 
    gamefacetemplate.startDrag(); 

    // listen mouse mouve event 
    gamefacetemplate.addEventListener(MouseEvent.MOUSE_MOVE, fl_ObjectPosition); 

    // listen mouse up event 
    stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); 
} 

function fl_ObjectPosition(event:MouseEvent):void 
{ 
    // test if the object is in a range of acceptable position 
    if(gamefacetemplate.x > 650 && gamefacetemplate < 750 && gamefacetemplate.y > 250 && gamefacetemplate.y < 350) 
    { 
     // place item at the right position 
     gamefacetemplate.x = 706; 
     gamefacetemplate.y = 311; 

     // stop dragging 
     gamefacetemplate.stopDrag(); 

     // and so remove the listeners 
     stage.aremoveEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); 
     gamefacetemplate.removeEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2); 
     gamefacetemplate.removeEventListener(MouseEvent.MOUSE_MOVE, fl_ObjectPosition); 

     // and maybe activate next step 
     gotoAndStop(5); 
    } 
} 

function fl_ReleaseToDrop(e:MouseEvent):void 
{ 
    // stop dragging 
    gamefacetemplate.stopDrag(); 

    // replace item at original position 
    gamefacetemplate.x = originalPos.x; 
    gamefacetemplate.y = originalPos.y; 

    // and so remove the listeners 
    stage.aremoveEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); 
    gamefacetemplate.removeEventListener(MouseEvent.MOUSE_MOVE, fl_ObjectPosition); 
} 

,或者如果你想在降位置激活下一步:

gamefacetemplate.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2); 

// maybe you want to keep te original position of the dragin object 
var originalPos:Point; 

function fl_ClickToDrag_2(event:MouseEvent):void 
{ 
    // keep original position 
    originalPos = new Point(gamefacetemplate.x, gamefacetemplate.y); 

    // start dragging 
    gamefacetemplate.startDrag(); 

    // listen for mouse up event 
    stage.addEventListener(MouseEvent.MOUSE_UP, fl_ObjectPosition); 
} 

function fl_ObjectPosition(event:MouseEvent):void 
{ 
    // maybe here you want to stop dragging 
    gamefacetemplate.stopDrag(); 

    // test if the object is in a range of acceptable position 
    if(gamefacetemplate.x > 650 && gamefacetemplate < 750 && gamefacetemplate.y > 250 && gamefacetemplate.y < 350) 
    { 
     // place item at the right position 
     gamefacetemplate.x = 706; 
     gamefacetemplate.y = 311; 

     // and so remove the listeners 
     stage.aremoveEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); 
     gamefacetemplate.removeEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2); 

     // and maybe activate next step 
     gotoAndStop(5); 
    } 
    else 
    { 
     // replace item at original position 
     gamefacetemplate.x = originalPos.x; 
     gamefacetemplate.y = originalPos.y; 
    } 
}