2 Replies Latest reply on Jul 22, 2009 2:19 AM by Sportbiker12

    How? Flash buttons to load new SWF in placeholder movieclip

    Sportbiker12

      I'm not a great Flash expert by any means, but I think I can clearly explain my problem and maybe someone can guide me. I'll lay out it clean and fast. All of this is actionscript 2, NOT 3. I have my opening page which is one big SWF with flash buttons on it. When this swf loads, I have a action on frame 1 of my timeline that reads:

       

      loadMovie("homepage.swf", "placeHolder_mc");

       

      It loads the swf into the movieclip placeholder and plays just fine!

       

      My problem now seems to be understanding proper syntax for button actions. My objective is to have each flash button load a different SWF into the placeHolder_mc, but it's not working.

       

      I've tried:
      on (press) {
      loadMovie("about.swf", "placeHolder");
      }

       

      but it doesn't work at all. I've even tried variations, but I really seem to be overlooking something probably due to lack of knowledge. I'm wondering if I have to unload a movieclip before loading another one, or perhaps I'm totally overlooking some proper structure or scripting. Any tips would be SOOOOO appreciated!

        • 1. Re: How? Flash buttons to load new SWF in placeholder movieclip
          chrisatflash Level 1

          hi, aren't you making a spelling error?
          First you call it: placeHolder_mc when loading the external swf in the placeholder and on the button event : placeHolder

           

          I also would suggest to put the code on the timeline and give your button an instance name.

           

          For example your button name is: mybutton

           

          The code would be:

           

          mybutton.onRelease = function() {

           

           

               loadMovie("homepage.swf", "placeHolder_mc");

           

          }

           

          regards, Chris.

          • 2. Re: How? Flash buttons to load new SWF in placeholder movieclip
            Sportbiker12 Level 1

            Thank you for your help! It was a struggle, but you pointed me in the right direction; ultimately solving the problem and giving me an education along the way. I'm not sure if there's another way to do this, but what I discovered was that placing my actionscript for the movieclip "button" IN the movieclip itself just wouldn't work.

             

            I want to post what I did in case someone else is seeking the same information trying to create a movieclip button. I found many tutorials on this, but a lot of them were "bits and pieces" and it just wasn't clear enough for a hack like me. I know I find everyone else's posts extremely helpful, so I hope this helps others.

             

            Background
            I'm use to to traditional buttons where Flash has the (4) states (up, over, down, hit). In this case, I discovered the joy of movieclip buttons, allowing me to create gentle glowing on the over state and a long fade on the out state. They're not really "buttons" in the traditional way some of us think. They're movieclips with actionscript that makes your movieclip behave like a button.

             

            Step One - Build Your Movieclip "button" timeline
            Create a movieclip that represents the behavior and timeline of what you want that button to do. Random example:
            Frame 1 represents the "up state"
            Frame 2 to 7 represents the "over" state, perhaps a glowing highlight
            Frame 8 to 20 represents the "out" state, perhaps where that highlight fades away

             

            Step Two - Add Frame Labels and Stop Actions in Your Movieclip
            What's really cool (and I never knew about this) is the use of Frame Labels (see image). Frame labels can actually be referenced (and they will be) for the actionscripting to come. So, add a new layer in this movieclip, call it labels (or whatever) and place a label on the two frames that coincides with the "over" and "out" stages of your movieclip behavior. To be specific, put a frame label on frame 2 called "over" and put a frame label on 7 called "out".

             

            Done? Okay! This is the part that tripped me up. Don't add any actionscript in this movieclip except one: stop actions! In the image shown, you'll see I added a stop action on Frame 1(up state) and frame 7(over state). Your movieclip is done. Now, go back to original Scene/Stage. We're not working in the button anymore.

            buttons.jpg

             

            Step Three - Actionscripting (I'm using AS2)
            Place your button, excuse me, movieclip, on the stage and give it an Instance name. In my example, I called it "aboutButton".

             

            Add actionscript for this movieclip on the Scene timeline (not in the movieclip itself). Below is the code I used in my button. Note that the instance name for the movieclip is referenced and the frame labels we added are also referenced in the actionscrtipting as well.

             

            this.aboutButton.onRollOver = function () {
                aboutButton.gotoAndPlay("over");
            }

             

            this.aboutButton.onRollOut = function () {
                aboutButton.gotoAndPlay("out");
            }

             

            this.aboutButton.onRelease = function () {
                loadMovie("about.swf", "placeHolder_mc");
            }

             


            In this case, you'll see I'm using the "onRelease" function to load a SWF into a placeholder. That's simply what I needed my button to do, but you can code that function to your liking and need. I sure hope this helps someone!

             

            Thanks!