# Is there an event probelm in actionscript?

**URL:** <https://forum.kirupa.com/t/is-there-an-event-probelm-in-actionscript/7826>\
**Category:** Uncategorized\
**Created:** [November 8, 2002, 3:19pm UTC](https://forum.kirupa.com/t/is-there-an-event-probelm-in-actionscript/7826 "2002-11-08T15:19:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sala](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sala](https://forum.kirupa.com/u/sala)\
**Post date:** [November 8, 2002, 3:19pm UTC](https://forum.kirupa.com/t/is-there-an-event-probelm-in-actionscript/7826/1 "2002-11-08T15:19:49Z")

</div>

Hi community

I am currently trying to set up a small piece of software in flash mx. Having experience in OOP / javascript, I stumble over some basic problems, but I think it’s not because of actionscript but because of my ignorance. Thus, any help is highly appreciated.

Here’s the simple problem.

Imagine some simple code like this:

// start code

this.createEmptyMovieClip(“firstClip”,1);  
with (this.firstClip) {  
beginFill(0x000000,100);  
moveTo(10,10);  
lineTo(10,50);  
lineTo(50,50);  
lineTo(50,10);  
endFill();  
}

this.firstClip.createEmptyMovieClip(“secondClip”,2);  
with (this.firstClip.secondClip) {  
beginFill(0x333333,100);  
moveTo(20,20);  
lineTo(20,170);  
lineTo(170,170);  
lineTo(170,20);  
endFill();  
}

this.firstClip.onPress = function() {  
trace(“clicked first”);  
}

this.firstClip.secondClip.onPress = function() {  
trace(“clicked second”);  
}

//end code

I would expect that If I click on the secondClip (in gray), the eventhandler on _this_ clip would react and trace “clicked second”. However, I only get “clicked first”, even though I clicked on the second one.

How can I change this? I want the “clicked first” message to appear only when I clicked on the first clip, and the “clicked second” message only when I click on the second.

Attaching both of the clips on the root is not an option. Later, I want to make the the whole package of attached clips draggable, that’s why I attach one to the other.

Thanks a lot for your help!

sala

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 8, 2002, 7:16pm UTC](https://forum.kirupa.com/t/is-there-an-event-probelm-in-actionscript/7826/2 "2002-11-08T19:16:12Z")

</div>

it’s the nesting that’s causing the problem. since secondClip is part of firstClip, the press event never makes it down the hierarchy.

if you want to avoid putting them in \_root, perhaps putting them both in a third clip, and not nested in each other, would solve some problems.

```auto

this.createEmptyMovieClip("zeroClip",0);
this.zeroClip.createEmptyMovieClip("firstClip",0);
with (this.zeroClip.firstClip) {
   beginFill(0x000000,100);
   moveTo(10,10);
   lineTo(10,50);
   lineTo(50,50);
   lineTo(50,10);
   endFill();
}

this.zeroClip.createEmptyMovieClip("secondClip",1);
with (this.zeroClip.secondClip) {
   beginFill(0x333333,100);
   moveTo(20,20);
   lineTo(20,170);
   lineTo(170,170);
   lineTo(170,20); 
   endFill();
}

this.zeroClip.firstClip.onPress = function() {
trace("clicked first");
}

this.zeroClip.secondClip.onPress = function() {
trace("clicked second");
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 9, 2002, 10:15am UTC](https://forum.kirupa.com/t/is-there-an-event-probelm-in-actionscript/7826/3 "2002-11-09T10:15:59Z")

</div>

you’re right, that is a way to solve my problem. Thanks for the hint!

However, I am still a bit confused about this whole thing. It basically means that actionscript is not able to tell on which instance of a moveClip an event was fired (if the movieClips are nested).

If that is the case, then I think this is rather a huge flaw in actionscript. Any GUI is highly depending on such a mechanism. Hope this gets fixed in a new version…:-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 10, 2002, 8:38pm UTC](https://forum.kirupa.com/t/is-there-an-event-probelm-in-actionscript/7826/4 "2002-11-10T20:38:46Z")

</div>

not all events behave like onPress.

onPress effectively makes the movie act as a button, which masks press events for nested buttons. unless you use the ‘track as a menu’ switch to modify its behaviour.

an onMouseUp event will fire for all clips regardless of their nesting, but also regardless of the mouse position. combined with a hitTest you can emulate the onPress action but without the nesting problems.

or you can structure your movie such that onPress clips are not nested in other onPress clips.
