Skip navigation
Currently Being Moderated

Load a draggable MovieClip from an DropDown menu

May 4, 2012 10:27 AM

Tags: #as3 #movie #actionscript3 #drag #clip

hi all!

I got stuck on this little interface I'm doing. It's the first time I seriously code in as3 and I guess this is over my possibility at the moment!

What I'm trying to do is:

1) a dropDown menu that loads an HTML file when clicked and also a movie clip onto the stage (this part works ok)

2)the movieClip I loaded is draggable.... and here I rest my case!

I'm thinking that the key to make it work is to embed the code that makes it draggable inside the movie clip itself; this way when I load the MC it comes already draggable... is that correct?

The main code is this;




import flash.display.MovieClip;

import flash.sampler.NewObjectSample;



//define texts for the HEADING and for the PANEL's children (b1,2,3,4)

menu_event.heading.myText.text = "EVENT";

menu_event.panel.b1.myText.text = "press";

menu_event.panel.b2.myText.text = "pressNeighbour";

menu_event.panel.b3.myText.text = "bla";

menu_event.panel.b4.myText.text = "blabla";



menu_actions.heading.myText.text = "ACTIONS";

menu_actions.panel.b1.myText.text = "ledOn";

menu_actions.panel.b2.myText.text = "ledOff";

menu_actions.panel.b3.myText.text = "ledFlash";

menu_actions.panel.b4.myText.text = "ledDim";



menu_blocks.heading.myText.text = "BLOCKS";

menu_blocks.panel.b1.myText.text = "state";

menu_blocks.panel.b2.myText.text = "broadcast";

menu_blocks.panel.b3.myText.text = "onEntry";

menu_blocks.panel.b4.myText.text = "onExit";

//tell the MENU to do something depending on which target is clicked

menu_event.addEventListener(MouseEvent.CLICK, clickHandler);

menu_actions.addEventListener(MouseEvent.CLICK, clickHandler);

menu_blocks.addEventListener(MouseEvent.CLICK, clickHandler);





function clickHandler(event:MouseEvent):void


          if ( == menu_event.panel.b1)


                    navigateToURL(new URLRequest("event_1.html"));

                    // Create a new MovieClip

                    var myMovieClip:MovieClip = new event_obj();

                    // Add the new MovieClip to the MainTimeline

                    // so that we can see it.


                    // Set the location of the new MovieClip

                    myMovieClip.x = 150;

                    myMovieClip.y = 210;


          if ( == menu_event.panel.b2)


                    navigateToURL(new URLRequest("event_1.html"));


          if ( == menu_event.panel.b3)


                    navigateToURL(new URLRequest("event_2.html"));


          if ( == menu_event.panel.b4)


                    navigateToURL(new URLRequest("event_3.html"));


          //////////////////////////////////////////////////////////////// ////

          if ( == menu_actions.panel.b1)


                    navigateToURL(new URLRequest("actions_1.html"));


          if ( == menu_actions.panel.b2)


                    navigateToURL(new URLRequest("actions_2.html"));


          if ( == menu_actions.panel.b3)


                    navigateToURL(new URLRequest("actions_3.html"));


          if ( == menu_actions.panel.b4)


                    navigateToURL(new URLRequest("actions_4.html"));


          //////////////////////////////////////////////////////////////// ////

          if ( == menu_blocks.panel.b1)


                    navigateToURL(new URLRequest("blocks_1.html"));


          if ( == menu_blocks.panel.b2)


                    navigateToURL(new URLRequest("blocks_2.html"));


          if ( == menu_blocks.panel.b3)


                    navigateToURL(new URLRequest("blocks_3.html"));


          if ( == menu_blocks.panel.b4)


                    navigateToURL(new URLRequest("blocks_4.html"));






kudos for the help

  • Currently Being Moderated
    May 4, 2012 10:59 AM   in reply to maxwelladdicted

    You could place the code inside the loaded movieclip or you could assign the code in the same section where you load it.

    Mark as:
  • Currently Being Moderated
    May 5, 2012 4:50 AM   in reply to maxwelladdicted

    If you have that code inside the object, then you are not really dragging the object, you are dragging something inside it that has the instance name mc_test, and even then you might not be actually moving mc_test, but whatever graphic/object is inside of it..


    If you monitor the x and y properties of myMovieClip as you drag they probably don't change.  Put this listener at the end of the clickHandler functionto check that...


         myMovieClip.addEventListener(MouseEvent.MOUSE_MOVE, checkXY);


    and add this function to process it... outside the function


        function checkX(evt:MouseEvent):void {
               trace(evt.currentTarget.x, evt.currentTarget.y)


    If your intention is to move the myMovieClip object, then you want to change that code inside the object to...



         buttonMode = true;


         // Register mouse event functions

         addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

         addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);


         // Define a mouse down handler (user is dragging)

         function mouseDownHandler(evt:MouseEvent):void {




         function mouseUpHandler(evt:MouseEvent):void {




    Just in case, assigning buttonMode is not necessary unless you wish to have the cursor change to a hand when moving over the object.

    Mark as:
  • Currently Being Moderated
    May 5, 2012 7:09 AM   in reply to maxwelladdicted

    First thing you need to do is avoid nesting functions within functions.  I know why you are probably doing it, but doing it is bad practice that will lead to troubles you will not understand how they happen when they do.


    Anything that involves managing the objects you create is better done outside of the objects.


    If you only want to remove that last child added, then you probably want to add them into an array and target the last element of the array.


    Another option could be to use removeChildAt(numChildren-1);, but the hazard there is that you could end up removing beyond the first one added as well.


    You do not need to be assigning that KEY_DOWN event listener more than once.  YOu do not need to create a new one each time you create an new instance.


    In any case, you seem to be willing to experiment, which is a good thing.  Try things and see what works and what doesn't... that's the best way to learn... having solutions handed to you doesn't have the same impact as something you struggle with and evolve.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points