[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
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();
};
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
I've only got MX2004 and can't open you fla.
hi dawsonk... 2004 version attached...
Attached Files
Last edited by dawsonk; 09-03-2008 at 02:24 PM .
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!!
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
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
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
Forum Rules
Click Here to Expand Forum to Full Width