7 Replies Latest reply on Apr 23, 2009 2:33 PM by kglad

    Dynamicly adding script

    Desprez10 Level 1

      Ok, I figured out how to add and swap movieclips during runtime, but how do I insert script into it?

        • 1. Re: Dynamicly adding script
          kglad Adobe Community Professional & MVP

          add movieclips from where?  the library?  if yes, use attachMovie().  if external swf files, use loadMovie or loadMovieNum() or loadClip().

           

          and what movieclips do you want to "swap".  an on-stage movieclip with a library movieclip or external movieclip.

           

          and what do you mean by inserting script into something?  you want to apply actionscript to a run-time creation?

          • 2. Re: Dynamicly adding script
            Desprez10 Level 1

            I already figured out how to add and swap movieclips, I wasn't asking about them.

             

            Yes, I want to as actionscript to a run-time creation.

            For instance, I add a movieclip to the stage using attachMovie() and I want it to respond to mouse clicks. Somehow I need to insert code into it.

             

            I could have sworn I saw something about it when I wasn't looking for it. But now my searches are turning up blank, so I must be using the wrong search terms.

             

            OH! wait a sec... I think you did that in a peice of code you posted in a different topic.

            Let me see, how about this...

             

            Say I now have a movieclip instance names "myMovie", I add stuff by:

             

            myMovie.onRelease = function()

            //code here

            };

             

            Is this correct?

            • 3. Re: Dynamicly adding script
              kglad Adobe Community Professional & MVP

              when you create a movieclip using attachMovie(), you assign it an instance name.  use that code for mouse handlers or use the return from attachMovie():

               

              var mc:MovieClip=this.attachMovie("linkageID","instanceName",depth);

               

              // 1.

              this[instanceName].onRelease=function(){

              //do whatever

              }

               

              // or

               

              // 2.

              mc.onRelease=function(){

              // do whatever

              }

              • 4. Re: Dynamicly adding script
                Desprez10 Level 1

                Ok, I thought I was starting to figure out actionscript's eccentricities, and then this happens...

                I have no script that adds handlers to the movieclip produced by attachMovie(), and yet the movieclip is appearing with functionality?

                 

                I click a button, and it makes a new movieclip appear. When I click on the new movieclip, it does stuff, even though I haven't given it any on (release) code yet? Um...?

                 

                Additionaly, the movieclip seemes to be stored in the library with child parts already added to it, and I can't 'open' it up anymore by double-clicking on it. Am I to understand that scripts made during authoring are saved to a movieclip even if that clip is deleted from the stage?

                 

                EDIT: double-clicking opens up the movieclip again. It must have been some strange glitch.

                • 5. Re: Dynamicly adding script
                  kglad Adobe Community Professional & MVP

                  is this thread closed or do you still have some problems scripting new created movieclips?

                  • 6. Re: Dynamicly adding script
                    Desprez10 Level 1

                    I just didn't realize that movieclips retained code while they were in the library. So I don't need to add code to run-time created movieclips in the first place anymore. So I guess it's closed.

                    • 7. Re: Dynamicly adding script
                      kglad Adobe Community Professional & MVP

                      ok.