# Add eventlistener to embedded movieclip AS3

**URL:** https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016
**Category:** flash
**Created:** [May 11, 2008, 5:43pm UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016 "2008-05-11T17:43:31Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![phillyrob](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@phillyrob](https://forum.kirupa.com/u/phillyrob)
#### Post date: [May 11, 2008, 5:43pm UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/1 "2008-05-11T17:43:31Z")

</div>

How can I addeventlistener to a movieclip embedded in another to where both the parent and the child will respond to a mouse event in AS3? The parent movieclip will move while the child changes alpha.

---

<div class="post-metadata">

### Author: ![bLaf](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@bLaf](https://forum.kirupa.com/u/bLaf)
#### Post date: [May 11, 2008, 6:38pm UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/2 "2008-05-11T18:38:39Z")

</div>

Try

```auto
ParentMovieClip.mouseChildren = false;

```

That way, events which are targeting child objects will get fired, but the target will be the parent.

---

<div class="post-metadata">

### Author: ![phillyrob](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@phillyrob](https://forum.kirupa.com/u/phillyrob)
#### Post date: [May 11, 2008, 7:06pm UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/3 "2008-05-11T19:06:12Z")

</div>

[quote=bLaf;2324726]Try

```auto
ParentMovieClip.mouseChildren = false;

```

That way, events which are targeting child objects will get fired, but the target will be the parent.[/quote]

I’ll try it. Thanks

---

<div class="post-metadata">

### Author: ![adnan794](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@adnan794](https://forum.kirupa.com/u/adnan794)
#### Post date: [May 11, 2008, 7:14pm UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/4 "2008-05-11T19:14:05Z")

</div>

If your movieclip is a child of another movieclip then you can register the parent movieclip for listener and in that listener function you can call event.currentTarget this will give the the child movieclip which is inside the other so by registering one listener you can do both things you want moving the parent and changing alpha for the child.

---

<div class="post-metadata">

### Author: ![snickelfritz](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@snickelfritz](https://forum.kirupa.com/u/snickelfritz)
#### Post date: [May 11, 2008, 8:22pm UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/5 "2008-05-11T20:22:45Z")

</div>

[QUOTE=phillyrob;2324702]How can I addeventlistener to a movieclip embedded in another to where both the parent and the child will respond to a mouse event in AS3? The parent movieclip will move while the child changes alpha.[/QUOTE]  
Here’s the basic concept:  
“parent1” clip is the target for the event listener.  
Event propagation causes the children of “parent1” to receive events directed at “parent1”.  
“parent1” is tweened within the function triggered by the child clips, “child1” and “child2”.

```auto
//on the stage: movieclip "parent1" contains movieclips "child1" and "child2"
stop();
import gs.TweenMax;
import fl.motion.easing.*;
var button:String = "";

parent1.addEventListener(MouseEvent.MOUSE_OVER, rollover, false, 0, true);
parent1.addEventListener(MouseEvent.MOUSE_OUT, rollout, false, 0, true);

function rollover(event:MouseEvent):void {
	button = event.target.name;
	TweenMax.to(event.target, 1, {alpha:.5});
	TweenMax.to(parent1, .2, {x:120, ease:Linear.easeIn});
	trace(button);
}

function rollout(event:MouseEvent):void {
	button = event.target.name;
	TweenMax.to(event.target, 1, {alpha:1});
	TweenMax.to(parent1, 1, {x:100, ease:Elastic.easeOut});
	trace(button);
}

```

---

<div class="post-metadata">

### Author: ![phillyrob](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@phillyrob](https://forum.kirupa.com/u/phillyrob)
#### Post date: [May 11, 2008, 8:31pm UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/6 "2008-05-11T20:31:13Z")

</div>

[quote=snickelfritz;2324753]Here’s the basic concept:  
“parent1” clip is the target for the event listener.  
Event propagation causes the children of “parent1” to receive events directed at “parent1”.  
“parent1” is tweened within the function triggered by the child clips, “child1” and “child2”.

ActionScript Code:  
[LEFT][COLOR=#808080]_//on the stage: movieclip “parent1” contains movieclips “child1” and “child2”\</p\>_[/COLOR]  
\<p\>stopCOLOR=#000000[/COLOR];\</p\>  
\<p\>import gs.[COLOR=#000080]TweenMax[/COLOR];\</p\>  
\<p\>import fl.[COLOR=#000080]motion[/COLOR].[COLOR=#000080]easing[/COLOR].\*;\</p\>  
\<p\>var [COLOR=#0000ff]button[/COLOR]:[COLOR=#0000ff]String[/COLOR] = [COLOR=#ff0000]""[/COLOR];\</p\>  
\<p\>&nbsp;\</p\>  
\<p\>parent1.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE\_OVER[/COLOR], rollover, [COLOR=#000000] **false** [/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>parent1.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE\_OUT[/COLOR], rollout, [COLOR=#000000] **false** [/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;\</p\>  
\<p\>function rolloverCOLOR=#000000[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;button = event.[COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]name[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;TweenMax.[COLOR=#000080]to[/COLOR][COLOR=#000000]([/COLOR]event.[COLOR=#0000ff]target[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000000]{[/COLOR]alpha:.[COLOR=#000080]5[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;TweenMax.[COLOR=#000080]to[/COLOR][COLOR=#000000]([/COLOR]parent1, .[COLOR=#000080]2[/COLOR], [COLOR=#000000]{[/COLOR]x:[COLOR=#000080]120[/COLOR], ease:Linear.[COLOR=#000080]easeIn[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;traceCOLOR=#000000[/COLOR];\</p\>  
\<p\>[COLOR=#000000]}[/COLOR]\</p\>  
\<p\>&nbsp;\</p\>  
\<p\>function rolloutCOLOR=#000000[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;button = event.[COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]name[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;TweenMax.[COLOR=#000080]to[/COLOR][COLOR=#000000]([/COLOR]event.[COLOR=#0000ff]target[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000000]{[/COLOR]alpha:[COLOR=#000080]1[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;TweenMax.[COLOR=#000080]to[/COLOR][COLOR=#000000]([/COLOR]parent1, [COLOR=#000080]1[/COLOR], [COLOR=#000000]{[/COLOR]x:[COLOR=#000080]100[/COLOR], ease:Elastic.[COLOR=#000080]easeOut[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;traceCOLOR=#000000[/COLOR];\</p\>  
\<p\>[COLOR=#000000]}[/COLOR]  
[/LEFT]

[/quote]

Thanks Snickelfritz, I will try to digest and implement you code.

---

<div class="post-metadata">

### Author: ![phillyrob](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@phillyrob](https://forum.kirupa.com/u/phillyrob)
#### Post date: [May 12, 2008, 6:39am UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/7 "2008-05-12T06:39:43Z")

</div>

> [@phillyrob;2324740](#):
>
> I’ll try it. Thanks

Thanks, but I am not following. Can you give me an example? Here is some simple code that is on the root or parent timeline. I have a movieclip called recTangle, Inside the movieclip recTangle, I have a movieclip called bluerecTangle. I want the movieclip recTangle to move and at the sametime I want the embedded movieclip bluerecTangle to change alpha to = 0;

recTangle.addEventListener(MouseEvent.ROLL\_OVER, rollOver1);  
recTangle.addEventListener(MouseEvent.ROLL\_OUT, rollOut1);  
function rollOver1(event:MouseEvent):void  
{  
recTangle.x += 50;

}  
function rollOut1(event:MouseEvent):void  
{  
recTangle.x -= 50;  
}

---

<div class="post-metadata">

### Author: ![phillyrob](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@phillyrob](https://forum.kirupa.com/u/phillyrob)
#### Post date: [May 12, 2008, 6:40am UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/8 "2008-05-12T06:40:28Z")

</div>

> [@adnan794;2324742](#):
>
> If your movieclip is a child of another movieclip then you can register the parent movieclip for listener and in that listener function you can call event.currentTarget this will give the the child movieclip which is inside the other so by registering one listener you can do both things you want moving the parent and changing alpha for the child.

Thanks, but I am not following this. Can you please give me an example? Here is some simple code that is on the root or parent timeline. I have a movieclip called recTangle, Inside the movieclip recTangle, I have a movieclip called bluerecTangle. I want the movieclip recTangle to move and at the sametime I want the embedded movieclip bluerecTangle to change alpha to = 0;

recTangle.addEventListener(MouseEvent.ROLL\_OVER, rollOver1);  
recTangle.addEventListener(MouseEvent.ROLL\_OUT, rollOut1);  
function rollOver1(event:MouseEvent):void  
{  
recTangle.x += 50;

}  
function rollOut1(event:MouseEvent):void  
{  
recTangle.x -= 50;  
}

---

<div class="post-metadata">

### Author: ![phillyrob](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@phillyrob](https://forum.kirupa.com/u/phillyrob)
#### Post date: [May 12, 2008, 6:48am UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/9 "2008-05-12T06:48:50Z")

</div>

[quote=snickelfritz;2324753]Here’s the basic concept:  
“parent1” clip is the target for the event listener.  
Event propagation causes the children of “parent1” to receive events directed at “parent1”.  
“parent1” is tweened within the function triggered by the child clips, “child1” and “child2”.

ActionScript Code:  
[LEFT][COLOR=#808080]_//on the stage: movieclip “parent1” contains movieclips “child1” and “child2”\</p\>_[/COLOR]  
\<p\>stopCOLOR=#000000[/COLOR];\</p\>  
\<p\>import gs.[COLOR=#000080]TweenMax[/COLOR];\</p\>  
\<p\>import fl.[COLOR=#000080]motion[/COLOR].[COLOR=#000080]easing[/COLOR].\*;\</p\>  
\<p\>var [COLOR=#0000ff]button[/COLOR]:[COLOR=#0000ff]String[/COLOR] = [COLOR=#ff0000]""[/COLOR];\</p\>  
\<p\>&nbsp;\</p\>  
\<p\>parent1.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE\_OVER[/COLOR], rollover, [COLOR=#000000] **false** [/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>parent1.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE\_OUT[/COLOR], rollout, [COLOR=#000000] **false** [/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;\</p\>  
\<p\>function rolloverCOLOR=#000000[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;button = event.[COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]name[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;TweenMax.[COLOR=#000080]to[/COLOR][COLOR=#000000]([/COLOR]event.[COLOR=#0000ff]target[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000000]{[/COLOR]alpha:.[COLOR=#000080]5[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;TweenMax.[COLOR=#000080]to[/COLOR][COLOR=#000000]([/COLOR]parent1, .[COLOR=#000080]2[/COLOR], [COLOR=#000000]{[/COLOR]x:[COLOR=#000080]120[/COLOR], ease:Linear.[COLOR=#000080]easeIn[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;traceCOLOR=#000000[/COLOR];\</p\>  
\<p\>[COLOR=#000000]}[/COLOR]\</p\>  
\<p\>&nbsp;\</p\>  
\<p\>function rolloutCOLOR=#000000[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;button = event.[COLOR=#0000ff]target[/COLOR].[COLOR=#0000ff]name[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;TweenMax.[COLOR=#000080]to[/COLOR][COLOR=#000000]([/COLOR]event.[COLOR=#0000ff]target[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000000]{[/COLOR]alpha:[COLOR=#000080]1[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;TweenMax.[COLOR=#000080]to[/COLOR][COLOR=#000000]([/COLOR]parent1, [COLOR=#000080]1[/COLOR], [COLOR=#000000]{[/COLOR]x:[COLOR=#000080]100[/COLOR], ease:Elastic.[COLOR=#000080]easeOut[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
\<p\>&nbsp;&nbsp;&nbsp;&nbsp;traceCOLOR=#000000[/COLOR];\</p\>  
\<p\>[COLOR=#000000]}[/COLOR]  
[/LEFT]

[/quote]

How could I do it with is code:

Here is some simple code that is on the root or parent timeline. I have a movieclip called recTangle, Inside the movieclip recTangle, I have a movieclip called bluerecTangle. I want the movieclip recTangle to move and at the sametime I want the embedded movieclip bluerecTangle to change alpha to = 0;

recTangle.addEventListener(MouseEvent.ROLL\_OVER, rollOver1);  
recTangle.addEventListener(MouseEvent.ROLL\_OUT, rollOut1);  
function rollOver1(event:MouseEvent):void  
{  
recTangle.x += 50;

}  
function rollOut1(event:MouseEvent):void  
{  
recTangle.x -= 50;  
}

---

<div class="post-metadata">

### Author: ![bLaf](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@bLaf](https://forum.kirupa.com/u/bLaf)
#### Post date: [May 12, 2008, 8:45am UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/10 "2008-05-12T08:45:08Z")

</div>

[quote=phillyrob;2324918]Thanks, but I am not following. Can you give me an example? Here is some simple code that is on the root or parent timeline. I have a movieclip called recTangle, Inside the movieclip recTangle, I have a movieclip called bluerecTangle. I want the movieclip recTangle to move and at the sametime I want the embedded movieclip bluerecTangle to change alpha to = 0;

recTangle.addEventListener(MouseEvent.ROLL\_OVER, rollOver1);  
recTangle.addEventListener(MouseEvent.ROLL\_OUT, rollOut1);  
function rollOver1(event:MouseEvent):void  
{  
recTangle.x += 50;

}  
function rollOut1(event:MouseEvent):void  
{  
recTangle.x -= 50;  
}[/quote]

Here’s my version 😃

```auto
 recTangle.addEventListener(MouseEvent.ROLL_OVER, rollOver1);
recTangle.addEventListener(MouseEvent.ROLL_OUT, rollOut1);
recTangle.mouseChildren = false;

function rollOver1(event:MouseEvent):void
{
recTangle.x += 50;
// two ways to deal with it:
recTangle.bluerecTangle._alpha = 0;
// or
//event.currentTarget.bluerecTangle._alpha = 0;

}
function rollOut1(event:MouseEvent):void
{
recTangle.x -= 50;

recTangle.bluerecTangle._alpha =100;
// or
// event.currentTarget.bluerecTangle._alpha = 100;

}

```

---

<div class="post-metadata">

### Author: ![phillyrob](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@phillyrob](https://forum.kirupa.com/u/phillyrob)
#### Post date: [May 12, 2008, 1:57pm UTC](https://forum.kirupa.com/t/add-eventlistener-to-embedded-movieclip-as3/260016/11 "2008-05-12T13:57:26Z")

</div>

[quote=bLaf;2324948]Here’s my version 😃

```auto
 recTangle.addEventListener(MouseEvent.ROLL_OVER, rollOver1);
recTangle.addEventListener(MouseEvent.ROLL_OUT, rollOut1);
recTangle.mouseChildren = false;
 
function rollOver1(event:MouseEvent):void
{
recTangle.x += 50;
// two ways to deal with it:
recTangle.bluerecTangle._alpha = 0;
// or
//event.currentTarget.bluerecTangle._alpha = 0;
 
}
function rollOut1(event:MouseEvent):void
{
recTangle.x -= 50;
 
recTangle.bluerecTangle._alpha =100;
// or
// event.currentTarget.bluerecTangle._alpha = 100;
 
 
}

```

[/quote]

Thanks 1 million this works pefectly!. I changed the code \_alpha to alpha to work in AS 3 but it works. You are a life saver. Thanks again.
