A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [RESOLVED] add a button to a draggable mc?

  1. #1
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55

    resolved [RESOLVED] add a button to a draggable mc?

    i'm trying to add a button to a draggable mc... but the actionscript to make the mc drag is not allowing the button to function.

    this is the script i have:

    Code:
    mcPostItIntro.mcPostIt.btClose.onPress = function() {
    	mcPostItIntro.gotoAndPlay('out');
    };
    mcPostItIntro.onPress = function() {
    	startDrag("mcPostItIntro", false, -600, -600, 15000, 270);
    };
    mcPostItIntro.onRelease = function() {
    	stopDrag();
    };
    where mcPostItIntro is mc to drag and btClose is the instance name i've given the button over a close "x" icon.

    any ideas how i can get a button (that has to drag with the mc) can allow the mc to play and fade out the mc?

    cheers

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Nested on press functions won't work.

    Consider changing to a parallel approach. Example, use a child movie of mcPostItIntro (shown below as 'bg') as the hit area for the on press/release functions and still have the start drag function drag the entire movie.

    Code:
    mcPostItIntro.mcPostIt.btClose.onPress = function() {
    	mcPostItIntro.gotoAndPlay('out');
    };
    mcPostItIntro.bg.onPress = function() {
    	startDrag("mcPostItIntro", false, -600, -600, 15000, 270);
    };
    mcPostItIntro.bg.onRelease = function() {
    	stopDrag();
    };

  3. #3
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    thanks dawsonk!

  4. #4
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    mmm... thought i'd sorted this but evidently not!

    here's the fla file if anyone can help... it still doesn't allow the button to be pressed whilst dragging... tried dawsonk's suggestion but don't think i've done it correctly.

    cheers
    Attached Files Attached Files

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518
    I've only got MX2004 and can't open you fla.

  6. #6
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    hi dawsonk... 2004 version attached...
    Attached Files Attached Files

  7. #7
    :
    Join Date
    Dec 2002
    Posts
    3,518
    See attached file...
    Last edited by dawsonk; 09-03-2008 at 02:24 PM.

  8. #8
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    that's brilliant... thanks dawsonk!!

    i just tweaked it a little by moving the stop command along the timeline when the post-it has disappeared so the "button" action isn't picked up after it has closed.

    i'm going to try and apply this to the other post-its i've created (prob after the footy), so hopefully this thread IS resolved!

    thanks again for your help!!

  9. #9
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    final, final question!!
    the close script moves the post-it off in a direction to the top left...

    Code:
    var dist = 1000;
    var speed = 25;
    var old_x = mcPostIt._x;
    var new_x = mcPostIt._x - dist;
    var old_y = mcPostIt._y;
    var new_y = mcPostIt._y - dist;
    mcPostIt.onEnterFrame = function() {
    	var alpha = (speed);
    	if (old_x > new_x) {
    		mcPostIt._x -= speed;
    		old_x = mcPostIt._x;
    		mcPostIt._y -= speed;
    		old_y = mcPostIt._y;
    		mcPostIt._alpha -= alpha;
    		allow = 1;
    	} else {
    		allow = 0;
    		mcPostIt.enabled = true;
    		delete mcPostIt.onEnterFrame;
    	}
    };

    how can i get it to move/fade to the bottom right?? tried a few things but it then just disappears without moving or the fade.

    cheers

  10. #10
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Also make sure that each instance of the movie clip in the tween layer has the name 'mcPostIt' .
    Code:
    var dist = 1000;
    var speed = 25;
    var old_x = mcPostIt._x;
    var new_x = mcPostIt._x + dist;
    var old_y = mcPostIt._y;
    var new_y = mcPostIt._y + dist;
    mcPostIt.onEnterFrame = function() {
    	var alpha = (speed / 10);
    	if (old_x < new_x) {
    		mcPostIt._x += speed;
    		old_x = mcPostIt._x;
    		mcPostIt._y += speed;
    		old_y = mcPostIt._y;
    		mcPostIt._alpha -= alpha;
    		allow = 1;
    	} else {
    		allow = 0;
    		mcPostIt.enabled = true;
    		delete mcPostIt.onEnterFrame;
    	}
    };
    stop();
    HTH

  11. #11
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    superb, thanks once again dawsonk... only mod i made was to take the /10 off the 8th line so it faded out much faster.

    cheers

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