0

This is my ActionScript:

var containers = [
              option1Container,
              option2Container,
              option3Container,
              option4Container
             ];

for (var i = 0; i < containers.length; i ++) {
    containers[i].BlueBox.filters = [myShadowFilter]; 
   //BlueBox is an object inside the container. The above line adds a DropShadow to BlueBox

    containers[i].addEventListener(MouseEvent.MOUSE_OVER, optioniContainerOver);
    //give each item in the array the same mouse over and mouse out listener

    containers[i].addEventListener(MouseEvent.MOUSE_OUT, optioniContainerOut);
}

//create a color transform called optionOver
var optionOver:ColorTransform = new ColorTransform();
optionOver.color = 0xCC6600;


function optioniContainerOver(evt:Event):void {
containers[i].BlueBox.transform.colorTransform = optionOver; //this doesn't work.
}

Now, as you can see, what I'm trying to do with the function called optioniContainerOver is, that whenever a movieclip inside the containers array is hovered over, I want just that specific MovieClip to turn orange (0xCC6600). Is there a way for me to do this?

user2817200
  • 1,097
  • 2
  • 18
  • 38

1 Answers1

2

You'll want to take a look at the target of the event:

function optioniContainerOver(evt:Event):void {
    evt.target.BlueBox.transform.colorTransform = optionOver;
}

Depending on the composition of the displayObject firing the event, you may need to use currentTarget instead.

From the documentation:

The object that is actively processing the Event object with an event listener. For example, if a user clicks an OK button, the current target could be the node containing that button or one of its ancestors that has registered an event listener for that event.

Marcela
  • 3,728
  • 1
  • 15
  • 21
  • Hm, when I do that, it says 'TypeError: Error #1010: a term is undefined and has no properties. at MainTimeline/optioniContainerOver()' – user2817200 Jan 22 '14 at 14:21
  • okay, instead of evt.target, I changed it to evt.currentTarget and it worked.. you can change your answer and i'll mark it as answered.. here is a good explanation as to why it didn't work with target but worked with currentTarget, for future reference and if anyone else has this same issue: http://stackoverflow.com/questions/5921413/difference-between-e-target-and-e-currenttarget – user2817200 Jan 22 '14 at 14:24