2 Replies Latest reply on Aug 27, 2006 10:09 AM by WebXperience

    assign ActionScript to mc created by "createEmptyMC"


      I wonder if it is possible to assign actionscript to a movieclip wich is created by the "createEmptyMovieClip("test", 100);"

      the goal of my question is to make this new mc acting like a button: clicking on it must perform an action.

      can you help me out?
      thanks in advance
        • 1. Re: assign ActionScript to mc created by "createEmptyMC"
          Rothrock Level 5
          Why wouldn't it be. It is an instance of the MovieClip class. There are a couple things you will need to do.

          First here is a neat little trick. The createEmptyMovieClip method of the MovieClip class returns a reference to the new clip you created. For the example you have given here it isn't such a bit deal, butt it is a useful trick and if you learn it now you will find uses for it. So you can assign that name to a variable and use that variable again.

          trace("The current clip is: "+curClip);

          If this code is on the main timeline you should see a trace that says:

          The current clip is: _level0.test

          So then you can use that variable to attach the button-like actions:

          trace("You've clicked on "+this);

          Now the problem with this is something that a lot of folks seem to have a hard time grasping. It is called create EMPTYMovieClip for a reason, because the movieclip is empty and has nothing in it. Therefore there is nothing to onRelease on. So you will need to put something into the clip. A good choice for that is to use the Drawing API.

          Look it up in the help files. It is part of the MovieClip class so you will find it under that. Look for lineTo, moveTo, lineStyle, beginFill, and endFill. So after doing the create part you could do this:


          Now there will be a 20 x 20 red square inside the newly created clip. So there will be something to actually click on.
          • 2. Re: assign ActionScript to mc created by "createEmptyMC"
            WebXperience Level 1
            As you may already know the syntax for using createMovieClip is:

              path.createEmptyMovieClip(name, depth);

            So, for example: if you if you were to create a MovirClip named box_mc at the root level of your movie the syntax would look like:

            _root.createMovieClip("box_mc", 1);

            Then if you wanted to attach a new property, function, or another movie to it you would use the full pathname:

            level01.box_mc.onRelease () {
            gotAndStop(1); // Or any other instruction you wanted be performed upon pressing this movie which you've now given
            // the ability to respond to a Mouse Event.

            You could also, give it features like onReleaseOutside, onMouseOver, onClick or a slew of other cool mouse type attributesusing the same "full path" method. check out Help and invest in a good ActionScript book!