A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [help] "Selecting" duplicated movieclips

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    146

    [help] "Selecting" duplicated movieclips

    I'm having some problems making a real-time strategy game. So far I've made a map and placed the player's units on it.

    But now I need to select the units. I've tried a couple of things to get a variable (_root.selected) to hold the instance name instead of the source MC name.

    I've failed each time. I know for a fact that the instances exist, but for some reason the code in them isn't working.

    Is it even possible to have duplicated MCs interact with eachother, or on their own? I've used them in games before but that was also with just 1 MC for the user, and duplicated ones as enemies.

    In this case the duplicated MCs will be for both the user and the computer... Is it possible for them to interact or am I aiming way above flash's capabilities?

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    It should work. Duplicated mc's act same way as normal mc's.

    Explain what exactly are you trying to do and how have you built the movie.

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    sorry for taking so long to reply, i took a break from programming to get my head straight.

    I've attached a .FLA of the scene I'm working on. The placement of units and the map construction is done on Frame 1, Layer 5.

    The "selection" of the carrier unit is in _root.carrier to the top right of the screen

    I use flash 5. The code thats currently there is wayyyy off because I was getting frustrated and trying anything to make it work.

    I hope this helps you help me, because I REALLY want to finish this game!

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    You forgot to attach the fla.

  5. #5
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    i'll try again
    Attached Files Attached Files

  6. #6
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    This should work:
    code:

    onClipEvent (mouseDown) {
    if (this.hitTest(_root._xmouse, _root._ymouse,true)) {
    _root.selected = this._name;
    }
    }


    You dont need to make another variable "name", you can use movie clips instance name as it is.

    To check which ship is clicked, you can use _xmouse/_ymouse.

  7. #7
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    it works when you click on the source movieclip "carrier", but when you click on "car1" or "car2" (the duplicated MCs of "Carrier") _root.selected becomes null.

    any idea why?

  8. #8
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    It works on all duplicated mc's too when I test it. Maybe you forgot to delete the old code from other ships?

  9. #9
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    that doesn't seem to be it...

    i'm using flash 5.

  10. #10
    Senior Member Dusarn's Avatar
    Join Date
    Mar 2003
    Location
    TX
    Posts
    157
    Change the code Tonypa gave you to "onClipEvent(mouseUp)", and you can also get rid of your "onClipEvent (load)" code also. I was having the same problem as you until I changed that.. seems to be giving the correct names now.

  11. #11
    Senior Member
    Join Date
    Feb 2003
    Posts
    146
    I changed onClipEvent(mousedown) to onClipEvent(mouseup) and it works!

    thanks for all the help! (including help getting the .fla posted)

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