hey sziada!
Welcome to our lovely forums.
What you want to do is have your Pickup class handle all the Pickup instances (fancy word for 'single object of a class that has been created'). Not sure if you've created the Pickup class yourself, or had Flash automatically create it for you when you linked it to the Pickup MC. If it's the latter, to be able to edit the Pickup class, right-click Pickup MC in library and click 'Properties'. You should see a window. In the middle will be two pencil icons, next to two text boxes, one of which should say 'Pickup'. Click that one. You can now edit the class. Just make sure to save it wherever your .fla is.
Here's a sample of how your Pickup class should look like
ActionScript Code:
package {
import flash.display.MovieClip;
public class Pickup extends MovieClip {
public static var allPickupList = []; //static means it is independent of any one instance. you can look it up to understand better
public function Pickup() {
allPickupList.push(this); //this refers to the specific Pickup object just created. You want to have all Pickups in the allPickupList
}
public static function checkPickupCollisions(mc:MovieClip) {
for (var i = 0; i < allPickupList.length; i++) {
var tempPickup = allPickupList[i];
if (mc.hitTestObject(tempPickup)) //do whatever you want :)
}
}
}
}
Now in your main class you can loop through all the Pickups and see if box_mc has hit them. (If you don't have a main class, you should. It makes your life much easier, especially if you're creating a game. The role of a main
class is to control all other classes/objects on-screen and centralize your code). But if you don't have one now, you can just put this on the timeline
ActionScript Code:
addEventListener(Event.ENTER_FRAME,enterFrame);
function enterFrame(e) {
Pickup.checkPickupCollision(box_mc);
}