2011-01-11 55 views
1

我在AS3工作具體,但我覺得這是一個非常不可知的問題。1通過第三個對象將對象鏈接到另一個對象,在知道其他對象的基礎上,如何查找第三個對象?

具體來說,我有一個可以被連接到其他領域的物體領域的物體。它們通過第三個對象鏈接。我希望能夠僅通過關於當前鏈接在一起的2個球體對象的知識來查找鏈接對象。你會如何處理這個問題?

我想有一個唯一的標識字符串存儲在每個球體對象,只是爲了避免全球性檢查,以確保它們是唯一的......但如果它歸結到它不反對這個想法。

-----解決方案------

這裏是我結束瞭解決方案:

private function breakAtomicBonds(p_interactiveMatter:InteractiveMatter):void 
{ 
    var matchAmount:int; 
    var key:Object; 
    var atom:InteractiveMatter; 
    var constraint:Constraint; 
    var atoms:Vector.<InteractiveMatter>; 
    var atomVOs:Vector.<InteractiveMatterVO>; 
    var bond:InteractiveMatterVO; 
    var bondIndex:int; 
    var i:int; 
    for(i = p_interactiveMatter.interactiveMatterVO.bonds.length - 1; i >= 0; i--) // each(bond in p_interactiveMatter.interactiveMatterVO.bonds) 
    { 
    bond = p_interactiveMatter.interactiveMatterVO.bonds[i]; 
    for(key in _constraints) 
    { 
     if(key is Constraint) 
     { 
      constraint = key as Constraint; 
      atoms = _constraints[key] as Vector.<InteractiveMatter>; 
      atomVOs = new Vector.<InteractiveMatterVO>; 

      for each(atom in atoms) 
      { 
       atomVOs.push(atom.interactiveMatterVO); 
      } 

      matchAmount = 0; 

      if(atomVOs.indexOf(p_interactiveMatter.interactiveMatterVO) != -1) 
      { 
       matchAmount++; 
      } 

      if(atomVOs.indexOf(bond) != -1) 
      { 
       matchAmount++; 
      } 

      if(matchAmount == 2) 
      { 
       trace('found constraint!'); 
       _physicsWorld.removeConstraint(constraint); 
       delete _constraints[constraint]; 

       for each(atom in atoms) 
       { 
        bondIndex = atom.interactiveMatterVO.bonds.indexOf(bond) 
        if(bondIndex != -1) 
        { 
         atom.interactiveMatterVO.bonds.splice(bondIndex, 1); 
        } 
        bondIndex = atom.interactiveMatterVO.bonds.indexOf(p_interactiveMatter.interactiveMatterVO); 
        if(bondIndex != -1) 
        { 
            atom.interactiveMatterVO.bonds.splice(bondIndex, 1); 
         } 
        } 

        break; 
       } 
      } 
     } 
    } 
} 
+0

我想創建一個以聯合對象爲關鍵字的字典,並且它存儲了它所連接的2個球體對象。 – gltovar 2011-01-11 02:20:13

回答

相關問題