I hate for my first post to be a thread but I didn’t know where else to turn with my dilemma. I have been trying to solve this problem for the last four days now and I can’t seem to really pin point the problem.
I’m trying to create a game. So far most of the game is done except for two parts of it.
I’m trying to generate plates that slide down a counter. Now, so far I have a method that randomly generates different plates (out of 3).
I have an event listener Enter frame to constantly update the plate’s x value until it hits a transparent square (where I want it to stop);
PROBLEM: but the mouse events that I gave the plates only stick to the newly created plate, and for some reason only the first plate seems to do the moving once its created, the other ones appear to be displayed at (0,0). Once a new one is created the older one just stays in the current x and y.
This is the code:
private function generatePlate() {
plateNumber=Math.ceil(Math.random()*3);
if (plateNumber==1) {
addLargePlate();
} else if (plateNumber==2) {
addMediumPlate();
} else if (plateNumber==3) {
addBowlMedium();
}
}
private function addLargePlate() {
var plateLarge=new PlateLarge ;
plateLarge.x=-79;
plateLarge.y=50;
plateList.push(plateLarge);
addChild(plateLarge);
plateLarge.addEventListener(MouseEvent.MOUSE_UP,plateMouseUp);
plateLarge.addEventListener(MouseEvent.MOUSE_OVER,plateMouseOver);
}
private function plateMouseMove(e:MouseEvent) {
plateList[number].addEventListener(Event.ENTER_FRAME,plateFrame);
function plateFrame(evt:Event) {
if (plateMouseStatus==true) {
plateList[number].x=mouseX;
plateList[number].y=mouseY;
}
}
}
private function plateMouseDown(e:MouseEvent) {
plateMouseStatus=true;
current_Item=plateList[number];
plateMoving=false;
}
private function plateMouseUp(e:MouseEvent) {
plateMouseStatus=false;
}
private function plateV() {
plateLarge.addEventListener(Event.ENTER_FRAME,plateSlide);
function plateSlide(e:Event):void {
if (plateLarge.hitTestObject(square)) {
plateTouch=true;
plateMoving=false;
}
if (plateMoving==true) {
if (plateTouch==false) {
plateLarge.x+=plateVelocity;
}
}
}
}
Hopefully the code is easy to read. I included the parts that I think seem to be the problem, if you prefer for me to include the whole text then let me know and I’ll post it in a reply.