View Full Version : Dragged movie clips - defining the order messages are displayed
rogerandout
10-23-2002, 10:15 PM
Interactivity question.
I have five nearly identical (different colours) movie clips on the stage and when I drag each one to a certain point a (different) message/picture appears.
So far so good.
But what I want to happen now is that one of the five messages appears last of all. I'm expecting each mc to be moved in turn until the message is displayed but I'm not expecting the mcs to be moved in any particular order. It doesn't matter in which order the mcs are moved and it doesn't matter in which order the messages are displayed as long as the last mc to be moved causes the particular (final) message to be shown.
Any ideas anyone ?
crabcake
10-24-2002, 12:55 AM
I'm presuming that you are using a hit test or coordinates to bring up the message when they drop the MCs on your target, which means that you have some sort of testing going on to detect this. In the script you are using to test that they have dropped the circle in the right place, you can increment a variable then test to see if this variable has reached 5 if they have dropped on the target:
_root.tracker += 1;
if(_root.tracker == 5){
tell whichever message you want to appear last to appear
}else{
tell a random selection of the other four messages to appear
}
I don't know what your messages are called or where they are situated, but the calls in the if-then-else statement could probably use the code you are currently using to call your messages, but excluding message 5.
Hope this helps.
rogerandout
10-27-2002, 08:39 PM
Thanks crabcake for your input.
I'm still having problems ;
Taking as an example 4 movieclips - on the main timeline first frame has this code :
_root.oldguy._visible = false;
_root.woman._visible = false;
_root.youngguy._visible = false;
_root.final._visible = false;
function newMessage(figure) {
tracker += 1 ;
vara1 = _root.oldguy ;
vara2 = _root.woman ;
vara3 = _root.youngguy ;
vara4 = _root.final ;
if(_root[figure]._y >= 280) && (tracker == 4) {
vara4._visible = true ;
} else if (_root[figure]._y >= 280) && (tracker != 4) {
i = Math.ceil(Math.random()*3);
(vara+i)._visible = true ;
}
}
The movie clips have invisible buttons enabling dragging, and there are actions on the mcs like this :
onClipEvent (mouseMove) {
_root.newMessage("guy")
}
The coding above doesn't seem to work and the tracker seems to race away because its linked to the mouse movement.
Can you see where I'm going wrong - I'm still new at this.
crabcake
10-28-2002, 02:51 PM
Hmm. I may be misunderstanding what you are trying to do, but let me put out what I think you're after and then how I would code it.
You have four movie clips, which I presume are your messages. You've set their visibility to false, andnow you want to bring them up if the user drags the appropriate movie clip to a certain position. Right? I might name them differently, since you are naming them in their instance name one way, only to rename them in your function, so unless you have another reason for naming them twice
_root.oldguy._visible = false;
_root.woman._visible = false;
_root.youngguy._visible = false;
_root.final._visible = false;
would become
_root.vara1._visible = false;
_root.vara2._visible = false;
_root.vara3._visible = false;
_root.vara4._visible = false;
Then attach a script to the button within each movie clip:
on(press){
this.startDrag(false);
}
on(release){
//this variable tells the function which MC has just been dropped
_root.drop = this._name;
this.stopDrag();
_root.newMessage();
}
Your function sits on the root, I presume, and you should see something like this:
/*Declare your first random value so you hve something to work with going into the function and also set your first tracker value (or reduce the max tracker value by 1 inside your function)*/
i = Math.ceil(Math.random()*3);
tracker = 1;
//then your function
function newMessage() {
if (this[drop]._y>=280) {
if (tracker == 4) {
vara4._visible = true;
} else {
/*your random number generator won't know if a message is already visible, so to stop it rying to make the same message visible more than once:*/
while (this["vara"+i]._visible == true) {
i = Math.ceil(Math.random()*3);
}
}
this["vara"+i]._visible = true;
tracker += 1;
}
}
This should do it. Good luck!
rogerandout
11-01-2002, 09:45 AM
Almost there !! Thanks.
Just to round off : Using the above code was fine but Flash choked on the code if the dragged mcs were moved again after the messages had come up. So I decided to make them disappear at the moment the messages come up - so thats ok.
Next problem is that only one message should be visible at one time; so I positioned the message mcs on top of each other and used a swap depths method to ensure the latest message is on top - only problem is that the final message refuses to come out on top and I can't see why .
Great if this last hitch could be fixed ?
The code so far :
topLevel = 4;
_root.vara1._visible = false;
_root.vara2._visible = false;
_root.vara3._visible = false;
_root.vara4._visible = false;
/*Declare your first random value so you hve something to work with going into the function and also set your first tracker value (or reduce the max tracker value by 1 inside your function)*/
i = Math.ceil(Math.random()*3);
tracker = 1;
//then your function
function newMessage() {
if (this[drop]._y>=280) {
if (tracker == 4) {
vara4._visible = true;
this.swapDepths(_root.topLevel);
} else {
/*your random number generator won't know if a message is already visible, so to stop it rying to make the same message visible more than once:*/
while (this["vara"+i]._visible == true) {
i = Math.ceil(Math.random()*3);
}
}
this["vara"+i]._visible = true;
tracker += 1;
/*dragged mc disappears after it reaches y>280*/
this[drop]._visible = false;
/*should ensure message on top ? */
this["vara"+i].swapDepths(_root.topLevel);
}
}
crabcake
11-01-2002, 01:08 PM
You set your variable topLevel in your script, but you're calling it from _root in your functions. It should be this["vara"+i].swapDepths(topLevel);
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.