# Trouble accessing newly created MC

**URL:** <https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845>\
**Category:** flash\
**Created:** [December 30, 2003, 4:00pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845 "2003-12-30T16:00:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![daw0lverine](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@daw0lverine](https://forum.kirupa.com/u/daw0lverine)\
**Post date:** [December 30, 2003, 4:00pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/1 "2003-12-30T16:00:35Z")

</div>

Hi everybody, this is my first post here so I’ll try to be brief

I created a MC with a simple createMovieClip, in which I load a movie. This works.

[AS]  
\_root.createEmptyMovieClip(“pmpPlay”, 2);  
loadmovie(“play.jpg”, pmpPlay);  
pmpPlay.\_x = “20”;  
pmpPlay.\_y = “20”;  
pmpPlay.\_alpha = “100”;  
[/AS]

Now when I try to access it’s onMouseDown event, nothing is triggered.

[AS]  
\_root.pmpPlay.onMouseDown = function () {  
trace(“pmpplay click”);  
}  
[/AS]

Any idea ? I guess it’s all about the level on the createEmptyMovie function but I’m not sure.

Thanks in advance !

---

<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:** [December 30, 2003, 5:06pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/2 "2003-12-30T17:06:44Z")

</div>

Welcome to kirupa forum, daw0lverine! 😛

That’s because once the JPEG is loaded into the movie clip, most of its properties are set to their default value and event handlers are deleted. :-\

You could either 1) wait until the image has been fully loaded to define the event handler, or 2) create a child movie clip and load the image into it. 🙂

```auto
// 1
this.createEmptyMovieClip("pmpPlay", 2);
pmpPlay.loadMovie("play.jpg");
pmpPlay._x = 20;
pmpPlay._y = 20;
this.createEmptyMovieClip("preloader", 9876);
preloader.onEnterFrame = function() {
var loaded = pmpPlay.getBytesLoaded();
var total = pmpPlay.getBytesTotal();
if (loaded>0 && loaded == total) {
pmpPlay.onMouseDown = function() {
trace("pmpplay click");
};
this.removeMovieClip();
}
};
// 2
this.createEmptyMovieClip("pmpPlay", 2);
pmpPlay._x = 20;
pmpPlay._y = 20;
pmpPlay.onMouseDown = function() {
trace("pmpplay click");
};
pmpPlay.createEmptyMovieClip("image", 9876);
pmpPlay.image.loadMovie("play.jpg");

```

---

<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:** [December 30, 2003, 5:37pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/3 "2003-12-30T17:37:19Z")

</div>

Thanks a lot kode for your exhaustive answer.  
I user method #2 and it seems to work better indeed, yet I still have two problems :

1°) I have two layers : actions and preloader (preloader is not used yet), actions is the first one. The script you saw is executed in the actions layers.  
But in order to have my movieclip shown, it seems I need to specify \_root.createEmptyMovieClip(…) instead of this.createEmptyMovieClip(…).

2°) This problem is probably related to the first one : the onMouseDown event is triggered wherever I click on the movie. I tried to set the width and height of the created MC to minimum values but still.

Code : [AS]  
\_root.createEmptyMovieClip(“pmpPlay”, 2);  
pmpPlay.\_x = 20;  
pmpPlay.\_y = 20;  
pmpPlay.width = 11;  
pmpPlay.height = 9;  
pmpPlay.onMouseDown = function() {  
trace(“pmpplay click”);  
};  
pmpPlay.createEmptyMovieClip(“image”, 9876);  
pmpPlay.image.width = 11;  
pmpPlay.image.height = 9;  
pmpPlay.image.loadMovie(“play.jpg”);[/AS]

Any idea ?

Thanks in advance again

---

<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:** [December 30, 2003, 5:59pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/4 "2003-12-30T17:59:05Z")

</div>

1. I think it really shouldn’t make a difference… could you attach your FLA so I can check it out? 🙂

2. Use an [font=courier new]onPress[/font] or [font=courier new]onRelease[/font] event handler instead of the [font=courier new]onMouseDown[/font] handler? 😉

Also, you’re modifying the [font=courier new]\_width[/font] and [font=courier new]\_height[/font] properties before the image has been loaded…

> _Originally posted by kode_  
> \*_That’s because once the JPEG is loaded into the movie clip, most of its properties are set to their default value and event handlers are deleted. :-\*_

---

<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:** [December 30, 2003, 6:10pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/5 "2003-12-30T18:10:04Z")

</div>

Yes thanks you again for your help, the zip containing the fla and jpg files is attached.

---

<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:** [December 30, 2003, 6:18pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/6 "2003-12-30T18:18:53Z")

</div>

…See? I told you it wouldn’t make any difference. 😉

```auto
this.createEmptyMovieClip("pmpPlay", 2);
pmpPlay._x = 20;
pmpPlay._y = 20;
pmpPlay.onPress = function() {
	trace("pmpplay click");
};
pmpPlay.createEmptyMovieClip("image", 9876);
pmpPlay.image.loadMovie("play.jpg");

```

---

<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:** [December 30, 2003, 6:31pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/7 "2003-12-30T18:31:48Z")

</div>

Erm yes indeed i’ll theck in the original fla  
And for the fact that you can click anywhere and it triggers the onPress event of pmpPlay do you see where this comes from ?

---

<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:** [December 30, 2003, 6:45pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/8 "2003-12-30T18:45:44Z")

</div>

You didn’t delete the [font=courier new]onMouseDown[/font] handler from the code, just use the code I posted in my previous reply and it should work fine. 🙂

---

<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:** [December 30, 2003, 6:51pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/9 "2003-12-30T18:51:17Z")

</div>

Thanks ! You were of a great help you saved my day !

Thank you very much :DD

---

<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:** [December 30, 2003, 6:52pm UTC](https://forum.kirupa.com/t/trouble-accessing-newly-created-mc/38845/10 "2003-12-30T18:52:31Z")

</div>

You’re welcome. :beam:
