A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: multiple draggable MCs not working

  1. #1
    Senior Member
    Join Date
    Mar 2001
    Posts
    237

    multiple draggable MCs not working

    Hi.

    I have a simple problem. I have two different movieclips. Inside BOTH of the movieclips is a button (the same button, actually) with the same code:

    PHP Code:
    on(press) {
        
    drag=true;
    }
    on(releasereleaseOutside) {
        
    drag=false;

    Then on each movieclip I have the following code:

    PHP Code:
    onClipEvent(enterFrame){
        if (
    this.drag) {
            
    trace("clip1 drag = " this.drag);        
            
    this.startDrag();
        } else {
            
    this.stopDrag();
        }

    (note: the trace line reads "clip2 drag..." etc on the second clip.) Anyway, when I just put one of these on the stage, then it works fine. When I put the other one on there, then only one works! The output looks correct (always "clip1 drag = true" when I am supposedly dragging the first clip and "clip2 drag=true" when I'm dragging the second one). Anybody have any ideas why this isn't working?

    Here is the FLA if you want to play with it: dragtest.fla

    Thanks,

    ~j.
    Last edited by JLo; 02-28-2006 at 04:36 PM.

  2. #2
    Senior Member
    Join Date
    Mar 2001
    Posts
    237
    sorry to beg, but ANYBODY have any idea? It seems like such a simple thing, I can't even believe it's not working, or that nobody's run into this before.

  3. #3
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    JLo,

    The reason why your clips aren't both working, in my estimation, is because the keyword "this" is giving reference to "_level0" or "_root", not the clip itself.

    I would register the Library asset of the clip itself as a MovieClip subclass and configure its constructor to accomodate author-time instances. I'm snagging a copy of your file to see what I can do.

    +Q__
    Qwaizang \kw-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

  4. #4
    Senior Member
    Join Date
    Mar 2001
    Posts
    237
    Hi Q__Hybrid, thanks for your reply.

    If what you say is true, then if I changed the current trace statement to say "trace(this);" it would give me _root or _level0 in both instances.

    But when I run it it says "_level0.instance1" when I drag the first clip and "_level0.instance3" when I drag the second clip. So it seems to be referencing the correct MCs when it's dragging?

    Hmmm.. maybe I misunderstood what you meant? Anyway, let me know if you figure anything out with the FLA! Thanks again for your help!

    ~j.

  5. #5
    Senior Member
    Join Date
    Mar 2001
    Posts
    237
    I figured out a way to fix it. By taking out the "else { this.stopDrag(); }" from the mc and, instead, putting that code on the button... so "on(release, releaseOutside) { drag=false; this.stopDrag;}"

    However, I STILL don't understand why the way I did it before would break. When it says "this.stopDrag()" it's referring to the correct movieclip... so it shouldn't stop my dragging of the OTHER mc! It should have NOTHING to do w/ the other MC.. hmm.. so I'm still confused but at least I figured out a solution.

    Does anybody have a good explanation for this? Thanks,

    ~j.

  6. #6
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    JLo,

    sorry to give you bad news, but your FLA gave me "unexpected file format" and wouldn't run. I'm using MX 2004, in case we're running different versions.

    One thing that I overlooked before is that you aren't declaring "drag" as a local variable within your clips. Here's what I would do to fix your problem:

    In your button...
    PHP Code:
    on(press) {
      
    this._parent.drag true;
    }
    on(releasereleaseOutside) {
      
    this._parent.drag false;

    In your clip(s)...
    PHP Code:
    onClipEvent(load) {
      
    this.drag false;
    }
    onClipEvent(enterFrame) {
      if(
    this.drag) {
        
    this.startDrag();
      } else {
        
    this.stopDrag();
      }

    This should correct the problems you were having.

    +Q__
    Qwaizang \kw-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center