# Need help for game programming

**URL:** <https://forum.kirupa.com/t/need-help-for-game-programming/283887>\
**Category:** flash\
**Created:** [March 12, 2009, 3:38am UTC](https://forum.kirupa.com/t/need-help-for-game-programming/283887 "2009-03-12T03:38:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kristalize](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kristalize](https://forum.kirupa.com/u/kristalize)\
**Post date:** [March 12, 2009, 3:38am UTC](https://forum.kirupa.com/t/need-help-for-game-programming/283887/1 "2009-03-12T03:38:49Z")

</div>

I have a game that i’m doing and I need to addChild of a movieClip with 5 different characters store in the frames in it. The 5 characters are also movieClips with a set of animated states such as Sit,Stand,Walk in the frames of the respective characters. I have 5 buttons on the stage that will trigger addChild of the movieClip which will stop at the respective frame of the character. These characters will be draggable and drop into various placement on the stage and will be triggered to play the various animated states of the characters based on where they are placed.

What i have come up with so far

```
ActionScript Code:
[LEFT][COLOR=#0000FF]public[/COLOR] [COLOR=#000000] **function** [/COLOR] selectPassenger[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#0000FF]void[/COLOR] [COLOR=#000000]{[/COLOR]
        [COLOR=#000000] **var** [/COLOR] newChild:Passenger = [COLOR=#000000] **new** [/COLOR] Passenger[COLOR=#000000]([/COLOR]startX,startY[COLOR=#000000])[/COLOR];
        [COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000] **var** [/COLOR] i [COLOR=#0000FF]in[/COLOR] buttons[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
            [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]buttons[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#000080]mc[/COLOR] == event.[COLOR=#000080]currentTarget[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                newChild.[COLOR=#0000FF]gotoAndStop[/COLOR][COLOR=#000000]([/COLOR]i+[COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR];
                [COLOR=#808080]*//break;*[/COLOR]
            [COLOR=#000000]}[/COLOR]
        [COLOR=#000000]}[/COLOR]
        newChild.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_DOWN[/COLOR], dragStart[COLOR=#000000])[/COLOR];
        container.[COLOR=#000080]addChild[/COLOR][COLOR=#000000]([/COLOR]newChild[COLOR=#000000])[/COLOR];
    [COLOR=#000000]}[/COLOR]

```

[/LEFT]

this is the function for the buttons. Passenger is the movieClip that is exported. Within the Passenger movieClip is 5 frames with 5 movieClips of the different characters

```
ActionScript Code:
[LEFT][COLOR=#808080]*// dragging functions*[/COLOR]
    [COLOR=#0000FF]public[/COLOR] [COLOR=#000000] **function** [/COLOR] dragStart[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#0000FF]void[/COLOR] [COLOR=#000000]{[/COLOR]
        [COLOR=#0000FF]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]"drag start"[/COLOR][COLOR=#000000])[/COLOR];
        [COLOR=#0000FF]stage[/COLOR].[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_UP[/COLOR], dragStop[COLOR=#000000])[/COLOR];
        [COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000] **var** [/COLOR] i [COLOR=#0000FF]in[/COLOR] Passenger.[COLOR=#000080]passengers[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
            [COLOR=#0000FF]trace[/COLOR][COLOR=#000000]([/COLOR]i[COLOR=#000000])[/COLOR];
            [COLOR=#0000FF]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]"this"[/COLOR]+event.[COLOR=#000080]currentTarget[/COLOR][COLOR=#000000])[/COLOR];
            [COLOR=#0000FF]trace[/COLOR][COLOR=#000000]([/COLOR]Passenger.[COLOR=#000080]passengers[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR];
            [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]Passenger.[COLOR=#000080]passengers[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR] == event.[COLOR=#000080]currentTarget[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                Passenger.[COLOR=#000080]passengers[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#0000FF]gotoAndStop[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]"side"[/COLOR][COLOR=#000000])[/COLOR];
                Passenger.[COLOR=#000080]passengers[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#0000FF]startDrag[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
            [COLOR=#000000]}[/COLOR]
        [COLOR=#000000]}[/COLOR]
    [COLOR=#000000]}[/COLOR]

```

[/LEFT]

This is the function for the dragging of the child of Passenger onMouseClick. I need to target the correct movieClip within Passenger movieClip to gotoAndStop at the desired animation state.

Is there anyway for me to access the child that is set to animated state of the respective character or should i just change the code to hardcoding each buttons to each characters ?

Thanks for any help available ^^
