PDA

View Full Version : Movie Clips over another clips



saif3r
July 30th, 2009, 06:08 AM
Hello,
i got 3 movie clips on my logo and im using scale up and scale down for each other on Mouse_OVER and Mouse_OUT.
i would like to make scaled up logo to be on absolute top.
here is an ss:

http://img74.imageshack.us/img74/2340/flash.jpg

and here is the code:

import flash.events.MouseEvent;
var ACK:URLRequest = new URLRequest("http://ack.awfis.net/");

//ACK\\
ack.addEventListener(MouseEvent.CLICK, ackClick);

function ackClick(event:MouseEvent):void{
navigateToURL(ACK);
}

ack.addEventListener(MouseEvent.MOUSE_OVER, skalaup);

function skalaup(event:MouseEvent):void{
ack.scaleX +=0.6;
ack.scaleY +=0.6;
}
ack.addEventListener(MouseEvent.MOUSE_OUT, skaladown);

function skaladown(event:MouseEvent):void{
ack.scaleX -=0.6;
ack.scaleY -=0.6;
}could some1 gime me a clue ho to make it ?
ill be grateful. saif3r.

GrndMasterFlash
July 30th, 2009, 09:31 AM
here is a code snipet that will throw anything to the top of it's containers display list


function moveToTop(mc:MovieClip)
{
mc.parent.setChildIndex(mc, mc.parent.numChildren-1);
}

tomaugerdotcom
July 30th, 2009, 09:46 AM
whenever you add an element to the display list using addChild(), it becomes the "top" (ie: foremost) element. To change the depth of an element, you can use swapChildren() which takes 2 display objects as its parameters and exchanges their depths, or you can use setChildIndex().

In your example, since you have a fixed number of graphics that never changes, it sounds like setChildIndex() is the way to go.

In the example you provided, you want the object that is being scaled up to be in front. So in the skalaup() function, add something like
ack.setChildIndex(2);

This will take whichever object "ack" is referring to and put it in position #3. Now this will only work if you only have 3 objects within that display list (for example, if all three logo objects are sitting inside their own movie clip). Otherwise, you will have to figure out what their depths are first (assuming that the depths are static). You can find out an object's depth with getChildIndex().

Alternatively, if the depths are dynamic (that is, if you have a bunch of objects inside the same display list and you think that the number of objects may change at some point) then we need a more dynamic solution.

One alternative I can think of off the top of my head is to always store the object that was last positioned on top, and then swap the new object that's being scaled with that previous "top" object.

var topObj:Sprite;
then somewhere in your code, decide which of your "ack" objects will be the one that starts on the top (probably the last one you create)
topObj = Sprite (ack);

finally, in your skalaup() function:
swapChildren(ack, topObj);
topObj = Sprite(ack);

Note that I'm casting ack as a Sprite because I don't know from your example whether your ack objects are Sprites or MovieClips, so I'm playing it safe. You may not need this extra code.

Hope this sets you on the right track.

T

tomaugerdotcom
July 30th, 2009, 09:48 AM
I like GMF's solution better than mine, since the OP did say "absolute top", which is what GMF's solution does, whereas mine just swaps the depths within the group of the three "ack" objects. Plus it's simpler.

T

ilike2
July 30th, 2009, 10:00 AM
Place the logo on the topmost layer on the timeline.

saif3r
July 30th, 2009, 11:32 AM
yes but there are 3 logos. and each one of them will be enlarged and i would like to put them on top wheneven my mouse will be over specific logo

Krilnon
July 31st, 2009, 12:33 AM
Merged.