A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Accessing Child MC

  1. #1
    Member
    Join Date
    Jul 2008
    Posts
    37

    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

  2. #2
    Farmer divillysausages's Avatar
    Join Date
    Mar 2004
    Location
    ireland
    Posts
    251
    Code:
    function hitCheck(event:Event):void
    {
       if ( ball_mc.hitTestObject( container_mc.ground_mc ) )
       {
          ball_mc.y = ground_mc.y;
       }
    }

  3. #3
    Member
    Join Date
    Jul 2008
    Posts
    37
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center