I'm making a catching game and I only wanted the falling objects hit certain area on my catcher. My catcher is a girl with mouth open and I wanted the falling objects to hit only the mouth, not any other parts of her body like arms. So I made two objects, the full girl and just the mouth. How do I make the two objects (movieclips) move around with the mouse?
Here are the attached files.
Also, here is the actionscript code:
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
import flash.utils.getDefinitionByName;
public class CatchingSkittles extends MovieClip {
var girlmouthfront:GirlMouthFront;
var girlmouth:GirlMouth;
var nextObject:Timer;
var objects:Array = new Array();
var score:int = 0;
const speed:Number = 7.0;
public function CatchingSkittles() {
girlmouthfront = new GirlMouthFront();
girlmouthfront.y = 258.00;
addChild(girlmouthfront);
setNextObject();
addEventListener(Event.ENTER_FRAME, moveObjects);
}
public function setNextObject() {
nextObject = new Timer(1000+Math.random()*1000,1);
Display list? is that the display code under public class CatchingSkittles extends Movieclip?
Code:
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
import flash.utils.getDefinitionByName;
public class CatchingSkittles extends MovieClip {
var girlmouth:GirlMouth;
var girlmouthfront:GirlMouthFront;
var nextObject:Timer;
var objects:Array = new Array();
var score:int = 0;
const speed:Number = 7.0;
The display list is everything that shows up on stage. Everything that, if you go up parent by parent, you get to the stage. To put something on the display list, add it as a child of something that already is on the display list. In this case, you need to addChild(girlmouth).
And you shouldn't actually put void there. I didn't realize it was the constructor of a class. You can, but I find that case a little odd. In general though, you explicitly put the return type of a function in the declaration. If the function doesn't return anything, use void.
Thanks! the objects showed up. However, one object (girlmouth) is above the other object (girlmouthfront). I tried to adjust the height of girlmouth, but it moved both objects down instead of just the first object. Here's the code:
Code:
public function CatchingSkittles() {
girlmouthfront = new GirlMouthFront();
girlmouthfront.y = 258.00;
girlmouth = new GirlMouth();
girlmouth.y = 166.60;
addChild(girlmouth);
girlmouth.addChild(girlmouthfront);
setNextObject();
addEventListener(Event.ENTER_FRAME, moveObjects);
}
Yes, of course it moved both objects. That was the point of your question, how to get them to move together.
A display object's coordinates are relative to its parent. So by setting girlmouthfront.y = 258, you've told it to be 258 pixels below the origin of its parent, girlmouth.