currentTarget Child movieclip instance name

Greetings,

This my first post asking for assistance with AS3. I’ve been scouring the web for the past three days trying to find a solution, and I’m stumped!

Here is a link to the latest version of my FLA (http://www.see-g.net/flash/header.fla).

The code I am having trouble with is all the way at the bottom (Actions layer on the stage). Below the multi-line comment.

Basically, I have a rotating image bar. One the first level of my file, on the stage, is a container movie clip called “imageScroll”. The code that allows the images to rotate is applied to the container clip. Inside of “imageScroll”, are a series of 36 images, each with their own unique instance name.

On the main level, I have a block of code which first detects when the user mouses over imageScroll. Next my code attempts to dig down one level into imageScroll and find the instance name of the image the users mouse is hovering over. I want to then store that instance name in a string “_destination”, then take that string and store it in a MovieClip variable “currentClip”. By doing this, I can then use the variable currentClip to effect the code at the bottom, which causes the images to scale up when the user mouses over, and scale back when the user mouses out.

The way I currently have my file set up, the code always returns the instance name imageScroll. I am using event.currentTarget.name to try and pull the instance name of the image. I have tried using event.target.name, but that pulls the instance name of a movie clip two levels lower then I want to go.

I basically need a way to modify my code so it finds out which movie clip inside of the container imageScroll the user is mousing over.

For those who would prefer to have all the code here, see below:

//Import required flash packages
import flash.utils.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;

//Create a new Timer object, "myTimer"
//The number "10" means that the timer will tick every .01 seconds
var myTimer:Timer = new Timer(10);

//Variables that define the default, positive, negative, and stationary "x" direction velocities for the scrolling of the images.
var xVelDef = .25;
var xVelPos = 2;
var xVelNeg = -2;
var xVelZer = 0;

//Event listener to detect when "myTimer" is initialized, which then triggers defaultScroll,
//the function that causes the images to rotate at their default rate, as well as when the mouse leaves the stage.
myTimer.addEventListener(TimerEvent.TIMER, defaultScroll);

//Code to initialize myTimer
myTimer.start();

//Function that causes the images to rotate at their default rate
function defaultScroll(event:TimerEvent) {
    imageScroll.x += xVelDef;

    //if statement that causes the images to loop infinitely
    if (imageScroll.x > 935) {
        imageScroll.x = -585;
    }
}

//Function that contains the event listener to detect when the mouse leaves the stage, to resume default scrolling
function Start() {
    stage.addEventListener(Event.MOUSE_LEAVE, resumeScroll);
}

//Function that resumes the default scrolling of the images
//First it stops the main timer "myTimer", then starts it again, effectively resetting the timer
function resumeScroll(evt:Event):void {
    myTimer.stop();
    myTimer.start();
}

//Event listener to detect when the user mouses over the left arrow button
scrollLeft.addEventListener(MouseEvent.MOUSE_OVER, scrollLeftOver);

//Function to execute when the user mouses over the left arrow button
function scrollLeftOver(event:MouseEvent):void {

    //Create a new timer object, which will be tied to the new scroll rate
    var scrollLeftTimer:Timer = new Timer(10);

    //Event listener to detect when the new timer "scrollLeftTimer" is initialized
    scrollLeftTimer.addEventListener(TimerEvent.TIMER, timedLeftOver);
    
    //Code that stops "myTimer", effectively cancelling the default scroll function
    myTimer.stop();
    
    //Code that starts that scrollLeftTimer, increasing the scroll rate of the images
    scrollLeftTimer.start();

    //Function that causes the images to scroll to the right at an increase velocity
    function timedLeftOver(event:TimerEvent) {

        imageScroll.x = imageScroll.x + xVelPos;

        if (imageScroll.x > 935) {
            imageScroll.x = -585;
        }
    }
    
    //Event listener to detect when the mouse leaves the left scroll arrow
    scrollLeft.addEventListener(MouseEvent.MOUSE_OUT, scrollLeftOut);

    //Function that executes when the users mouse leaves the left scroll arrow
    function scrollLeftOut(event:MouseEvent):void {

        //When the scrollLeftTimer stops, the images cease to rotate
        scrollLeftTimer.stop();

        imageScroll.x += xVelZer;

        if (imageScroll.x > 935) {
            imageScroll.x = -585;
        }
    }
}

//Event listener to detect when the user mouses over the right arrow button
scrollRight.addEventListener(MouseEvent.MOUSE_OVER, scrollRightOver);

//Function to execute when the user mouses over the right arrow button
function scrollRightOver(event:MouseEvent):void {

    //Create a new timer object, which will be tied to the new scroll rate
    var scrollRightTimer:Timer = new Timer(10);

    //Event listener to detect when the new timer "scrollRightTimer" is initialized
    scrollRightTimer.addEventListener(TimerEvent.TIMER, timedRightOver);
    
    //Code that stops "myTimer", effectively cancelling the default scroll function
    myTimer.stop();
    
    //Code that starts that scrollRightTimer, increasing the scroll rate of the images
    scrollRightTimer.start();

    //Function that causes the images to scroll to the left at an increase velocity
    function timedRightOver(event:TimerEvent) {

        imageScroll.x = imageScroll.x + xVelNeg;

        if (imageScroll.x < -1420) {
            imageScroll.x = 100;
        }
    }
    
    //Event listener to detect when the mouse leaves the right scroll arrow
    scrollRight.addEventListener(MouseEvent.MOUSE_OUT, scrollRightOut);

    function scrollRightOut(event:MouseEvent):void {

        //When the scrollRightTimer stops, the images cease to rotate
        scrollRightTimer.stop();

        imageScroll.x += xVelZer;

        if (imageScroll.x < -1420) {
            imageScroll.x = 100;
        }
    }
}

//This code executes the function which causes the images to resume scrolling when the mouse leaves the stage
//Since the movie is looping on frame 1, this function is executed repeatedly.
Start();

/*
This block of code looks down one level in the imageScroll movieclip (Stage -> imageScroll -> target movieclip).
Depending on which image the user mouses over, the instance name of that image is stored in the variable "_destination".
After the function storeInstanceName has been called successfully, and the instance named has been stored,
that instance name will be used in the functions "scaleImageUp" and "scaleImageDown" to apply the tween to the images/buttons.
*/

var _destination:String;

//Event listener to detect when users mouses over container movieclip imageScroll.
imageScroll.addEventListener(MouseEvent.MOUSE_OVER, storeInstanceName);

//Function that reaches down one level into imageScroll, to retrieve the instance name of the image that is being moused over.
function storeInstanceName(event:MouseEvent):void {
    _destination = event.currentTarget.name;
    trace(_destination);
}

var currentClip:MovieClip = MovieClip(_destination);

//Event listeners to detect when the user rolls the mouse over and out of the image
currentClip.addEventListener(MouseEvent.ROLL_OVER, scaleImageUp);
currentClip.addEventListener(MouseEvent.ROLL_OUT, scaleImageDown);

//Function that eases/tweens the moused over image, scaled up
function scaleImageUp(event:MouseEvent):void {
    var xScale:Tween = new Tween(currentClip,"scaleX", Elastic.easeOut, currentClip.scaleX, 1.1, 1, true);
    var yScale:Tween = new Tween(currentClip,"scaleY", Elastic.easeOut, currentClip.scaleY, 1.1, 1, true);
}

//Function that eases/tweens the moused out image, scaled down
function scaleImageDown(event:MouseEvent):void {
    var xScale:Tween = new Tween(currentClip,"scaleX", Elastic.easeOut, currentClip.scaleX, 1, 1, true);
    var yScale:Tween = new Tween(currentClip,"scaleY", Elastic.easeOut, currentClip.scaleY, 1, 1, true);
}

Thanks in advance to anyone who may be able to help me!

  • Dave