8 Replies Latest reply on Jul 7, 2007 12:25 AM by DarthTurtle

    switch movie clips?

      Can you switch movie clips in flash using actionscript?
      And if you can, please tell me how.
        • 1. Re: switch movie clips?
          MaxManNH Level 2
          Could you describe in more detail what you mean by switch?
          • 2. Re: switch movie clips?
            DarthTurtle Level 1
            I am making a game that you can upgrade your weapon by clicking on a button.
            It's a spaceship game, and your spaceship shoots lasers. and I want to upgrade the lasers to bigger lasers when you click the button. And if you could switch movie clips then when you click the button, the regular laser would switch to the bigger laser movieclip.
            • 3. Re: switch movie clips?
              Rothrock Level 5
              Yes and no. The idea of switching doesn't really have a place in Flash. But you can hide one clip and then show another or have only one clip that has one version on frame one and the other on frame two and then switch between the frames.

              These would be the simplest ways of going about it. The same idea could be handled in far more complex ways, but the same basic ideas would apply.
              • 4. Re: switch movie clips?
                DarthTurtle Level 1
                Thanks for the suggestion. though I dont think that would work if it switched frames, the spaceship would be in a different place. wouldnt it?


                is the link to the game. If it would help any of you.
                The password is Halo
                use the arrow keys to move and the space bar to shoot.

                I want to be able to somehow "switch" the normal laser to a bigger one.
                I tried to make it so that when you click the upgrade, the laser would go to it's second frame, that had the bigger laser on it. But it didnt work. I couldnt figure out the actionscript.

                I tried putting

                _root.laser.gotoAndStop (2)

                as the actionscript on the button. but nothing happened. If this will work, then could someone tell me how to actionscript it?
                • 5. Re: switch movie clips?
                  Rothrock Level 5
                  The spaceship wouldn't be in a different spot if your artwork is drawn correctly and put together smartly. If it is part of the ship and needs to "stick" to the ship then I would have the various laser options drawn on their own frames within the laser movieclip and that would be on a layer above or below a movieclip perhaps of different body types of ships. Each keyframe of that clip would have the different artwork and also a stop(); in its actionscript panel.

                  You then should be able to upgrade by something along the lines of:


                  If that isn't working then I don't know why – that is totally basic actionscript. So there is probably something totally basic wrong. There is a typo. The clip you are referencing doesn't exist at the time it is referenced. There is a scoping issue.
                  • 6. Re: switch movie clips?
                    DarthTurtle Level 1
                    I put that action script in the button but nothing happened, and there wasn't an error message
                    the code on the laser is

                    onClipEvent (load) {

                    function reset(){



                    onClipEvent (enterFrame) {
                    if (this._name<>"laser"){
                    if (this._x>600){

                    for (i=1; i<=_root.numEnemy; i++){
                    if (this.hitTest( _root["enemy"+i])){
                    _root["enemy"+i].gotoAndPlay( 2 );



                    The code on the button is

                    on (release) {
                    if ( money < price) {
                    points -= 0
                    _root.display = "Insufficent Funds"
                    } else {
                    points -= 100


                    and on the frame the code is

                    price = 100

                    On the laser there are 2 frames, one has the regular laser, and the second has the upgraded laser. Both frames have the actionscript,


                    • 7. Re: switch movie clips?
                      Rothrock Level 5
                      Oh. You are using the old style on() handlers. I wouldn't even know where to begin to fix that other than to recommend you don't code like that. Here is a good article about it:


                      I'm sure it can be resolved somehow with your style of coding, but I really have no idea how.
                      • 8. Re: switch movie clips?
                        DarthTurtle Level 1
                        Oh...... But thanks for all your help.
                        I didn't make the script. I'm really a noob at actionscript. I just followed a tutorial on how to make it.
                        Do you know of any good places that i could learn flash from? A site that is free would be nice. I think this site should have a list of places that people can go to to learn Flash. I've been searching for a place, but i couldn't.