Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Personally, I would have an array/Vector (Vectors are much, much faster. Though they can be a royal pain to use) of objects within each individual zone. You keep this updated at all times. If you remove one, you use <code>splice(indexOf(obj),1)</code> to remove it from the array.</p> <p>For your problem, I would do this:</p> <pre><code>var p1:Sprite = new Sprite(); var p2:Sprite = new Sprite(); var zoneArray:Array = new Array();//there would be one for each zone, simplified it here //this code would run whenever an object enters the zone function zoneEnter(e:Event = null):void{ var currentZone:Sprite; //set this equal to the zone the sprite just entered var currentObject:Sprite = e.currentTarget as Sprite; //this way we know which object just entered currentZone if ( currentObject == p1 &amp;&amp; zoneArray.indexOf(p2) &gt;= 0 ) { //prevent it from entering the zone } if ( currentObject == p2 &amp;&amp; zoneArray.indexOf(p1) &gt;= 0 ) { //prevent it from entering the zone } } </code></pre> <p>There are obviously some limitations here if you are looking at a lot of objects. But if you know, for sure, there will only be two, I think this would be the way to go. If there will be more, you would need to create some kind of control structure that would allow you to check an object against other objects. I could elaborate and give a sample of what I am talking of here if it's needed. It's a tad bit complex, but not hard to implement.</p> <p>EDIT 10-17-12: Added in example code of how the more advanced logic would look.</p> <pre><code>var puzzleMap:Array = new Array(); var piece1:Piece = new Piece(); //this is the puzzle piece we'll be checking var piece2:Piece = new Piece(); var piece3:Piece = new Piece(); var piece1Objs:Array = [piece2,piece3]; var piece2Objs:Array = [piece1,piece3]; puzzleMap.push({piece:piece1,others:piece1Objs}); puzzleMap.push({piece:piece2,others:puzzle2Objs); private function stopDragHandler(e:MouseEvent = null):void{ var space:Space = space; //this is the space the object was dropped into (I don't know how you identify them, so this is pseudo code) var valid:Boolean = true; //we'll check for a bad drop since it's easiest if (event.target.dropTarget != null &amp;&amp; MovieClip(event.target.dropTarget.parent).allowed.indexOf(event.target) &gt; -1){ for ( var i:Number = 0; i &lt; puzzleMap.length; i++ ) { var current:Object = puzzleMap[i]; if ( current == e.currentTarget ) { for ( var j:Number = 0; j &lt; current.others.length; j++ ) { var checkAgainst:Piece = current.others[i] as Piece; if ( space.currentObjects.indexOf(checkAgainst) &lt; 0 ) { valid = false; break; } } } } if ( !valid ) { //prevent the drop here } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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