FORUMS: list search recent posts

Rollover and swapChildren Problems

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Lindsay Loeffler
Rollover and swapChildren Problems
on Jan 12, 2010 at 6:34:05 pm

Ok I have a Flash file with a square on one layer and on another layer right underneath is a map with an external link. My problem is that when you rollover the top square (it's a movie clip), it displays the map but the link does not work. I'm sure this is because I have it coded so that the movie clip is still there but not visible.

Here is the code for the rollover:

bc_mc.addEventListener(MouseEvent.MOUSE_OVER, showMap);

function showMap(event:MouseEvent):void
{
bc_mc.alpha = 0;
bc_mc.removeEventListener(MouseEvent.MOUSE_OVER, showMap);
bc_mc.addEventListener(MouseEvent.MOUSE_OUT, hideMap);
}

function hideMap(event:MouseEvent):void
{
bc_mc.alpha = 1;
bc_mc.addEventListener(MouseEvent.MOUSE_OVER, showMap);
bc_mc.removeEventListener(MouseEvent.MOUSE_OUT, hideMap);
}


I've been experimenting with addChild and swapChildren properties, but I'm still new to Actionscript 3.0 and Im having problems.

Here is the code I was experimenting with, and I know this completely wrong:

function swap (e:MouseEvent) {
e.target.parent.swapChildren(e.target, e.target.parent.getChildAt(e.target.parent.numChildren-1));
}

bc_mc.addEventListener(MouseEvent.MOUSE_OVER, swap);
map_mc.addEventListener(MouseEvent.MOUSE_OUT, swap);


Any help is greatly appreciated
Thanks, Lindsay


Return to posts index

cowcowcowcowcow
demetri tashie
Re: Rollover and swapChildren Problems
on Jan 14, 2010 at 5:53:31 pm

here's a way to go about it, using your line of reasoning. there are of course, other ways and approches to this problem.

this way utilizes a movieclip's 'visible' property as opposed to its 'alpha' property. if the alpha is set to 0, it appears invisible to us, but it is really still there in the display list covering up objects underneath it, whereas setting it's property to 'visibile=false' reveals what is underneath it .

also- for the way i will describe, make sure that the clip/button on top is either exactly the same size and in exactly the same position as the clip that is underneath, or make sure that it is smaller, but contained within the borders of the clip underneath it: : think of an oreo cookie that you took the top part off. you see the white filling(bc_mc) on top of the bottom part(myBtn) of the cookie : - )
otherwise you will get unexpected RollOver/RollOut behaviour


for this example there are 2 movieclips, one instance named 'myBtn' which will function as your map.
it will be scripted to be a clickable link to an external site ( i set it to google.com )
the other moviclip is instance named 'bc_mc' and sits on top of 'myBtn'

to make matters clear and clean, i start off giving 'myBtn' buttonMode capabilities- this way when testing, we get extra visual information as to if it is being recognized or not.
then i set the initial visibility of 'myBtn' to false, and 'bc_mc' to true.
this is not necessary, but it keeps things clear : when one is visible, the other is not. we could then use this as Boolean info and simplify our code, but i will leave that to another discussion..

the rest of the code should be pretty readable, but i will explain it as such:
bc_mc is given a listener and function for RollOver( or MouseOver) which makes bc_mc invisible, and the map(myBtn) visible. within the scope of this function, it also gives myBtn a CLICK listener to lead to the function to make it link to google.com, and a RollOut/MouseOut listener on myBtn which will take you to the function to reverse the visibilities( myBtn to false, and bc_mc to true.

once again, this is just one approach, using as much as possible your code and logic. i hope that helps you to understand and utilize it. if you need the .fla posted, just let me know


<pre>myBtn.buttonMode=true;
myBtn.visible=false;
bc_mc.visible=true;

bc_mc.addEventListener(MouseEvent.ROLL_OVER, showMap);
function showMap(event:MouseEvent):void
{
bc_mc.visible = false;
myBtn.visible=true;

myBtn.addEventListener(MouseEvent.CLICK, myBtnFunction);
function myBtnFunction(evt:MouseEvent):void{ navigateToURL(new URLRequest("http://www.google.com"));}
myBtn.addEventListener(MouseEvent.ROLL_OUT, hideMap);
}


function hideMap(event:MouseEvent):void
{
bc_mc.visible = true;
myBtn.visible=false;
}

function myBtnFunction(evt:MouseEvent):void{ navigateToURL(new URLRequest("http://www.google.com"));} </pre>




Return to posts index

Lindsay Loeffler
Re: Rollover and swapChildren Problems
on Jan 15, 2010 at 6:09:25 pm

Thank you so much, the code worked beautifully.

Lindsay


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]