9 Replies Latest reply on Jun 2, 2007 7:46 AM by Our_Tiny_Servant

    The SIMPLEST thing!

      I'm a beginner with Actionscript, but am comfortable with programming in other languages. I am creating a simple interface in Flash 8, and need to include some actionscript that I can apply to a button that will load a movieclip onto the stage from my library into a certain position. I have three buttons, in fact, and I want a movie to load that displays information about that button. Surely putting a movieclip onto the stage is easy?
        • 1. Re: The SIMPLEST thing!
          kglad Adobe Community Professional & MVP
          use the attachMovie() method of the movieclip class.

          you'll need to right click on your library movieclip, click linkage, tick export for actionscript, type an id in the appropriate box and click ok.

          then you'll need to use that id as the first parameter in attachMovie().
          • 2. Re: The SIMPLEST thing!
            dfm_ Level 1
            myButton_btn.onPress = function() {
            _root.attachMovie("id", "instanceName", _root.getNextHighestDepth());
            • 3. Re: The SIMPLEST thing!
              Our_Tiny_Servant Level 1
              Hi, thanks for the help. Could you break the code down for me? It doesn't seem to do anything. I have the code you gave me within the on(press) {} code of the button, I have a seperate movie clip on stage with an instance name that I've typed into the code instead of instanceName, and I have a movie clip in my library with linkage ticked and an id. What am I missing?
              • 4. Re: The SIMPLEST thing!
                Rothrock Level 5
                The instance name of your item on stage goes before the onPress. That is the thing you want clicked. Remember, onPress will be when the mouse button goes down, not back up.

                The id name is the id you gave the item in the library – not its library name, but the linkage ID is what you gave it in the export dialog. Make sure you've used the quote marks to make it a string – so many folks have that issue. Also make sure that you have the export in first frame checked.

                Finally the "insstanceName" is what you want your new instance to be called. So it can be anything you want. Not a good idea to use a name that already exists.
                • 5. Re: The SIMPLEST thing!
                  Our_Tiny_Servant Level 1
                  -shakes head- I know you're all trying so hard, and that I'm useless - but it's just not happening. Please keep helping...

                  So, I have a button on stage. Its instance name is simonbutton. I want this button to open another clip (simontext) somewhere else on the stage. This is the code i've attatched to it:

                  on (press) {
                  startDrag (this, true,100,100,900,600);
                  this.isDragging = true;
                  mostRecent = "simon";

                  simonbutton.onPress = function() {
                  _root.attachMovie("simonlink", "instanceName", _root.getNextHighestDepth());

                  Then, there is a clip on the stage with the instance name 'here'.
                  In the library I have a clip that has linkage ticked, it's called "simonlink" and first frame is ticked.

                  Ok, looking at the code, now, I see a few errors. I haven't even refered to the movieclip 'here'. I'm sure I need something on the stage to position the new, appearing clip to? Also, the code I've attatched to button refers to its own instance name. There is no point in this surely?
                  • 6. Re: The SIMPLEST thing!
                    Rothrock Level 5
                    With the code you've given us you should be getting an error.

                    Why are you using both on(press) and simonbutton.onPress? I'm guessing that is causing some trouble. the on(press) style of coding is a leftover from before 2001 and was replaced in Flash MX with the instance.onPress event handler that should go on a frame – not on an instance.

                    Anyways. You need to make sure to get all this code off your button. Then make sure you don't have your button selected. And select a key frame where this button exists. Most of us make a whole layer called actionscript and just put our actionscript on the frames of that layer.

                    Once you have a keyframe selected, open up your actionscript panel. At the top of the panel it should say something like Actions – Frame. If it says Actions – MovieClip or Button, then you know you aren't doing it right.

                    Next put your code in the frame it should look like what I have below. Don't worry about the other stuff yet, let's just get this working.

                    trace("Simon button pressed.");

                    So does it work? What do you get in the trace? You say in your post that the clip is called simontext, but in your code you are calling simonlink as the linkage ID. Just be sure that is correct.

                    Also, capitalization counts.

                    And here is a little trick that I think a lot of us use.



                    Look at each of those. In each pair, which do you find easier to read? Usually we start the names with lower case letters – we would start with uppercase if it was a class name – and then capitalize the first letter of each word. There are other ways to do it. So do what makes you happy, but DO get a convention and stick to it! :)
                    • 7. The SIMPLEST thing!
                      Our_Tiny_Servant Level 1
                      Okaaaay. So, I've been using old old old tutorials. I had an invisible button within a movie clip. An online tutorial taught me to 'combine the powers of both.' Clearly, Flash has come along quite a way - and I like what I'm seeing. A removed the button from within the clip, and all the code with it. I've now written the code I need on frame 1 of the main timeline on it's own Actions layer. The clip works perfectly, just as before - but still no movieclip appearing from the library. What connection will the movieclip in the library have with the (completely seperate) clip waiting on the stage, with the instance name 'here'? We're typing attachMovie, but attach to what? Or am I just getting the wrong idea entirely? Thanks for the advice with proper syntax too.


                      This is code so far. I tried using the co-ordinates suggestion in Flash Help.

                      _root.attachMovie("simonLink","instanceName",this.getNextHighestDepth(), {_x:100, _y:100});
                      trace("Simon button pressed.");

                      - edit -

                      Fantastic. I have it worked out. My linkage was filled out wrong. I wrote ""s inside it, which Flash didn't like. Thanks for your help.
                      • 8. Re: The SIMPLEST thing!
                        Rothrock Level 5
                        Glad you caught that because my first recommendation was going to be to go through and check for typos, spelling errors, and capitalization.

                        BTW, a few of the most helpful folks here use newsreaders to view the forum. Newsreaders won't show any edits, so if you need to make changes it is generally better just to post another reply. That way they can see the new information as well.
                        • 9. Re: The SIMPLEST thing!
                          Our_Tiny_Servant Level 1
                          What code would allow me to remove the clip from the stage?