2011-01-11 53 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

回答

相关问题