Note that there are some explanatory texts on larger screens.

plurals
  1. PO1 Object is linked to another Object though a third Object, how can I look up the third Object, based on knowing the 2 other Objects?
    text
    copied!<p>I'm working in AS3 specifically but I feel that this is a pretty agnostic question.</p> <p>Specifically I have sphere objects that can be linked to other sphere objects. They are linked though a third object. I would like to be able to look up the the linking object with only the knowledge of 2 sphere objects that are currently linked together. How would you approach this? </p> <p>I would like to having to store a unique identifier string in each sphere object, just to avoid a global check to ensure that they are unique... but not opposed to the idea if it comes down to it.</p> <p>----- solution ------</p> <p>here is the solution I ended up with:</p> <pre><code>private function breakAtomicBonds( p_interactiveMatter:InteractiveMatter ):void { var matchAmount:int; var key:Object; var atom:InteractiveMatter; var constraint:Constraint; var atoms:Vector.&lt;InteractiveMatter&gt;; var atomVOs:Vector.&lt;InteractiveMatterVO&gt;; var bond:InteractiveMatterVO; var bondIndex:int; var i:int; for( i = p_interactiveMatter.interactiveMatterVO.bonds.length - 1; i &gt;= 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.&lt;InteractiveMatter&gt;; atomVOs = new Vector.&lt;InteractiveMatterVO&gt;; 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; } } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload