[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


FLASH CS5.5 - ActionScipt - Bring to front on MouseOver

Posted on 2012-09-10
Medium Priority
Last Modified: 2012-09-11
Hi All,

I have several movieclips in my flash file, when i put my mouse over each movieclip that section of the image expands and changes colour.

The problem i have now is i need whatever element/layer i hover over to be brought to the front. At the moment, If i hover over a section it does expand as it should, however if there is another layer beneath it, the expand happens underneath the other layer.

So, to sum up i need a script which brings what ever layer is hovered over - to the top.

Please see attached image:

Many thanks,
Question by:Richiep86
  • 3
  • 2

Expert Comment

ID: 38383276

You don't say if you are using actionscript 2 or 3. This matters because they handle this ability in different ways.

The function is called swapDepths - see some discussion / code here - http://board.flashkit.com/board/showthread.php?618797-SwapDepth-Return-to-Original-Position-Animated-Buttons

The function is setChildIndex and you can see some code here - http://www.dzone.com/snippets/as3-swapdepths-equivalent

Author Comment

ID: 38383337
i believe it is As2.0

heres what i have:

// stops our animation

// whenever player enters frame, perform the actions between the curly brackets											 
this.onEnterFrame = function(){
	// if our zoom is "true", then previous frame (rewind)
	if(zoom == true){

// when mouse is over this symbol, perform the actions between the curly brackets
this.onRollOver = function(){
	// sets zoom as false, contradicting our "if" statement above, so it plays our clip
	zoom = false;

// when mouse is not over this symbol, perform the actions between the curly bracktes
this.onRollOut = function(){
	// sets zoom as true thus meeting the requirements of our "if" statement above
	// so it goes to the previous frame of our movie clip
	zoom = true;
button_mc.onRollOver = function() {
button_mc.onRollOut = function() {

Open in new window

I am completely new to flash - thanks for the help so far.

I could attach the flash if that helps?
LVL 19

Expert Comment

ID: 38383355
Sure - attaching the fla might be quickest. CS4 or earlier please... (File > Save as... might be needed)

Some people have reported issues with some filetypes and the EE upload system, so the most reliable way is to drop your fla into a zip file before uploading.
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database


Author Comment

ID: 38385806
I have attached the flash file in cs4 format - thank you for the help quizengine, much appreciated.

If i add an AS will i then need to name all of my movie files? I thought it would be fairly simply to bring the hoverered upon layer to the front - apparently not!

Thanks again
LVL 19

Accepted Solution

quizengine earned 2000 total points
ID: 38385888
I've edited the code on two symbols. You'll need to take these changes and do the same thing on each of the other symbols you want to have this behaviour.

What we're seeking to alter here is the 'z index' or 'depth' of the movieclip. When the clip is mouseovered, we want it's z index to be greater (a bigger number) than the other actors on the stage.

This is done with the line of code

     this.swapDepths(9999);// we're making the assumption that this is a big enough number

and when we mouseout we want to move the clip back from the front with


This is a 'quick and dirty' solution. In a perfect world, you'd probably want to keep track of all of your clips depths.

Double click the 'demand and portfolio management' clip, select the first frame, and look in the actions panel. I have entered the above code at lines 15 and 23. I have done the same with the 'Programme and Project management' clip so that as you pass your mouse between these two items when running the movie, you can see the swapDepths function in action.

You need to take these two lines of code and put them in a similar place for all of the other items that you want to have this behaviour.

Author Closing Comment

ID: 38385905

Thanks you soo much - cannot fault the support!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question