PDA

View Full Version : Drag + rollover effect similar to Windows Explorer



manky
March 28th, 2005, 09:29 AM
Hello all,

I was hoping to pick some brains here. Supposing you're in Windows Explorer (in WinXP that is), and you drag a file and hold it over the folder you're going to drop it into. Now, when you're holding it over the folder, the folder highlights.

How can I recreate this effect in Flash MX?

I have a "tile" movieclip, and a "container" movieclip. The tile is meant to be dragged into the container. In the situation where the tile is being dragged and held over the container (ie, mouse button has not been released), the container is meant to change colour.

Any ideas? Thanks in advance!

PCGamre
March 28th, 2005, 11:02 AM
Use hitTest:


onClipEvent (enterFrame) {
if (this.hitTest(_root.containerMC) {
_root.containerMC.gotoAndStop("containerIsGlowing");
}else {
_root.containerMC.gotoAndStop(1);
}
}

manky
March 29th, 2005, 06:54 AM
Thanks for that.

Is there any way for it to test for a sort of non-specific container?

What I mean is, the container(s) that I want to make "glow" are actually sitting within another movieclip (let's call it the "crate"). This "crate" movieclip that contains the containers can be duplicated by the user. This means that containers can be called anything from _root.crate_1.container to _root.crate_x.container, where "x" is whatever number the user duplicates up to. However, I want the glowing behaviour for all containers.

Any ideas? Thanks once again.

virusescu
March 29th, 2005, 07:12 AM
If you have multiple mc's in crate then you can access them like


for(x in crate){
trace(crate[x]);// this is the actual path for your mc.
}

soo combining with PCGamre's script this would probably look like

onClipEvent (enterFrame) {
for (x in _root.crate) {
if (this.hitTest(_root.crate[x])) {
if (_root.crate[x]._currentframe != 1) {
_root.crate[x].gotoAndStop("containerIsGlowing");
} else {
_root.crate[x].gotoAndStop(1);
}
}
}
}

Hope this works :)

manky
March 29th, 2005, 07:22 AM
Oh dear. I really didn't explain myself very well, sorry about that.

The "crate" movieclip contains 3 containers - "left container", "middle container" and "right container".

However, the "crate" movieclip can be duplicated by the user - crate1, crate2, and so on until the user decides to stop. So there can be lots of crates!

So basically I would like the "glow" in each container - left, middle and right - in each crate duplicated by the user.

Er, is this too confusing? Thanks once again!

virusescu
March 29th, 2005, 07:37 AM
Er, is this too confusing? Thanks once again!
Kind off :)

Sooo.. each crate has 3 containers. Each container glows when I move the mouse over the crate? or over one container in the crate?

Will you have other mc's in the root? besides the crates I mean?

virusescu
March 29th, 2005, 07:48 AM
Assuming that you will have multimple mc besides the crate in root, and that you don't know how many crates you have, even though you could increment a variable when you duplicate a crate ;)... the code could look something like this?


onClipEvent (enterFrame) {
for (x in _root) {
if (this.hitTest(_root[x]) && _root[x]._name.substr(0,5)=="crate") {
_root[x].container_left.gotoAndStop("containerIsGlowing");
_root[x].container_middle.gotoAndStop("containerIsGlowing");
_root[x].container_right.gotoAndStop("containerIsGlowing");
} else {
_root[x].container_left.gotoAndStop(1);
_root[x].container_middle.gotoAndStop(1);
_root[x].container_right.gotoAndStop(1);
}
}
}

So.. dragging "this" mc over a crate.. will make each container in that crate glow.
Note that the instace names of all the duplicated crates mcs should begin with "crate" ;)

manky
March 29th, 2005, 07:54 AM
Heheh, so sorry. I'll try to make myself clear:

Imagine one of those styrofoam packing crates that holds canned food. Each crate has 3 compartments for cans - ie, 3 cans per crate.

Now, I want to be able to drag a can into a crate's compartment (any of the three, doesn't matter). When I hold the can over the compartment, the compartment glows (to indicate that I can put the can there).

So, the user can have as many crates as they want - they click a button, and voila! A new empty crate!


Sooo.. each crate has 3 containers. Each container glows when I move the mouse over the crate? or over one container in the crate?

Each container glows when you move the mouse over that container only (the one the mouse is over).


Will you have other mc's in the root? besides the crates I mean?

Yes! The mc's for the "cans" will also be in the root, as well as a "trash" mc (to get rid of unwanted "crates").

Does this make any better sense at all? Thanks for your help!

virusescu
March 29th, 2005, 08:10 AM
I made you a quick example.
2 things I want you to notice. If you name your containers like container1 container2 and 3 instead of container_left etc... it's easyer to script.

Second... it's easyer to script and the processor has to do less checkings if we tell him how many crates there are in root, using that var cratesNo ;)

Take a look and tell me if it helps you.

manky
March 29th, 2005, 08:39 AM
THANK YOU!!!!!

It's a thing of beauty! It's precisely what I needed! Thanks so much! Okay, I'll stop with the exclamation marks now. But it suits the role perfectly, thank you for your time (and you did it so quickly too, I'm jealous).

virusescu
March 29th, 2005, 08:48 AM
Cool.. I'm glad I could help :)

KinZo
June 6th, 2005, 01:23 AM
You seem to know a lot. Can you help me with my AS problems? I need to recreate the widows effect where you click and start a transparent box, and from that point you can change the height and width of the box, and that box can be dragged over a lot of Icons at a time to do something to all of them.

virusescu
June 6th, 2005, 06:38 AM
You seem to know a lot.
Yes.. I seem :)

Can you help me with my AS problems?
I'll try to do my best.

Here's something to play with. I don't have much time on my hands right now (and even if I did.. I don't know what could I achieve more.)

I don't Know how to ... let's say, after you selected multiple icons to move them alll by dragging one single icon... - maybe after selecting them (putting them inside an mc?) don't know - this are my limits :).

But.. maybe this helps you. Cheers.