-
Accessing Child MC
Hi everyone,
Simple question...I think!
I'm creating a platform game, I want the ball to stay in the middle of the page while the background moves when the user presses the arrow keys, it looks like the ball is moving, but it's not.
To do this I have the ball in one movieclip and everything else (ground mc, enemies mcs, items mcs etc) in a container mc. So all I need to do is move the container left and right when the arrow keys are pressed, I can do that, no problem.
The problem occurs when I try to access the movieclips inside the container movieclip, for doing hit tests and such. The instance names come back as undefined.
If my container movieclip is named 'container_mc' and the ground movieclip is inside this named 'ground_mc' how would I change the below code to run the hittest?
stage.addEventListener(Event.ENTER_FRAME, hitCheck);
function hitCheck(event:Event):void
{
if (ball_mc.hitTestObject(ground_mc))
{
ball_mc.y = ground_mc.y;
}
}
Thanks a lot,
Ryan
-
Farmer
Code:
function hitCheck(event:Event):void
{
if ( ball_mc.hitTestObject( container_mc.ground_mc ) )
{
ball_mc.y = ground_mc.y;
}
}
-
Safe, Cheers, I knew it'd be easy, I started to try that but go put off by the coding assistant!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|