Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Recursive event handlers?

Posted on 2006-05-12
12
Medium Priority
?
153 Views
Last Modified: 2010-04-03
Hi,
I'm creating a game and need to drag-and-drop a movie clip while creating a duplicate on the same spot so the dragging can be done many times. This is approximately what I'm trying to do:

mc_num = 0;
mc0.onPress = doDrag;
mc0.onRelease = doDrop;

      function doDrag():Void {
         mc_num++;
         mc = this.duplicateMovieClip("mc"+mc_num, this.getNextHighestDepth());

        mc.onPress = doDrag;
        mc.onRelease = doDrop;
          this.startDrag();
      }

The problem is, looks like this kind of recursion doesn't work, so the new clip turns out to be not draggable. Is there any workaround here?
0
Comment
Question by:jgenyuk
  • 6
  • 5
12 Comments
 
LVL 19

Assisted Solution

by:Montoya
Montoya earned 200 total points
ID: 16670302
if you attach an instance of the movie from the library that already has that behavior coded, every instance will include the drag and drop behavior.

Do you know what I mean?

Montoya
0
 

Author Comment

by:jgenyuk
ID: 16671004
Montoya,
Thanks but this doesn't seem to work either. If I move the event handlers to the movie in library, the first instance works fine, but the one created at runtime doesn't drag. Tracing shows that the events handlers do get called so I'm completely mystified here.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16672492
Hi,


Let's assume your main movieClip instancename is "mc0"

Just replace your complete code with the following, it will work for you:
---------
mc_num = 0;
mc0.onPress = createNew;
mc0.onRelease = mc0.onReleaseOutside=function ()
{
      stopDrag();
};
//
function createNew()
{
      mc_num++;
      mc = mc0.duplicateMovieClip("mc"+mc_num, this._parent.getNextHighestDepth());
      startDrag(mc);
}
-----------

Rgds
Aneesh
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16672507
I have also uploaded a working sample for you which uses the same code as I suggested above

download it here:
http://download.yousendit.com/113993BE2571C7BC

Rgds
Aneesh
0
 

Author Comment

by:jgenyuk
ID: 16683517
Thanks, Aneesh, but in your sample the new movie clips do not inherit the dragging behavior, which is exactly my problem.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16683633
"inherit the dragging behavior" ?

could u please explain this point....?
0
 

Author Comment

by:jgenyuk
ID: 16683730
The newly created instances cannot be dragged again.
0
 

Author Comment

by:jgenyuk
ID: 16683742
..once they are dropped, I mean.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16683824
you mean to say, stage will have one movieClip, user drag it and a duplicate movieClip comes out of it...

now if user try to drag the newly created movieClip, it should also create a duplicate of itself and the new one should be dragged out..

if I understood it correctly, please confirm....
i will update the sample
0
 

Author Comment

by:jgenyuk
ID: 16683961
The new clip doesn't have to duplicate itself, it just has to be draggable as many times as the user feels like it. To explain better, this is a game where player creates new instances of an object by dragging it on the gameboard and then moves them around.
0
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 800 total points
ID: 16684003
Ok, here the code

open a new FLA,

create a new movieClip, place an instance on stage, name it "mc"


and place the following code on first framemee::
------
mc.onPress = createNew;
mc.onRelease = mc.onReleaseOutside=function ()
{
      stopDrag();
};
//
function createNew()
{
      mc_num++;
      newMc = mc.duplicateMovieClip("mc"+this._parent.getNextHighestDepth(), this._parent.getNextHighestDepth());
      startDrag(newMc);
      newMc.onPress = function()
      {
            startDrag(this);
      };
      newMc.onRelease = newMc.onReleaseOutside=function ()
      {
            stopDrag();
      };
}

----------

Rgds
Aneesh
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16684247
I have also uploaded the new sample here:
http://download.yousendit.com/32BC81671AC330E4

Rgds
Aneesh
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question