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

Posted on 2012-09-10
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
    LVL 4

    Expert Comment


    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 -

    The function is setChildIndex and you can see some code here -

    Author Comment

    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

    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.

    Author Comment

    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

    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


    Thanks you soo much - cannot fault the support!

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure ( It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
    In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
    The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Click on Too…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now