# Push and pop

**URL:** <https://forum.kirupa.com/t/push-and-pop/251512>\
**Category:** Uncategorized\
**Created:** [February 9, 2008, 11:29am UTC](https://forum.kirupa.com/t/push-and-pop/251512 "2008-02-09T11:29:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kutalinelucas](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kutalinelucas](https://forum.kirupa.com/u/kutalinelucas)\
**Post date:** [February 9, 2008, 11:29am UTC](https://forum.kirupa.com/t/push-and-pop/251512/1 "2008-02-09T11:29:16Z")

</div>

hi, i was wondering if i could get a bit of help. i have a flash application where the player move clip can collide with 4 objects which will then trail it, the only trouble is i only want one object to trail at any one time…

so far i have tried creating an array, where a collected (trailing) object is “pushed” when collected then popped off the array when its dropped (when it collides with another movie clip). now im trying to put in a if statement where only if the array is empty another item can be collected, but i don’t know where i’m going wrong, or even if this is the best way to do it

var inventory = new Array();

if(inventory.length == 0)

{  
pickup object  
inventory.push(objectA);  
}  
if(object dropped)

{  
pop off object // so inventor array is now empty

}

}

i can post the segment of code if this is unclear

thanks for looking
