# Mc.onPress not working w/ createEmptyMC

**URL:** <https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118>\
**Category:** Uncategorized\
**Created:** [March 11, 2004, 5:18am UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118 "2004-03-11T05:18:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jubba](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@Jubba](https://forum.kirupa.com/u/Jubba)\
**Post date:** [March 11, 2004, 5:18am UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/1 "2004-03-11T05:18:58Z")

</div>

This code isn’t working for me. I have written the same thing a bazillion times, but for some reason this isn’t working for me right now…:

```auto

this.createEmptyMovieClip("container", -1);
for (ii=0; ii<xml_obj.firstChild.childNodes.length; ii++) {
                container.duplicateMovieClip("cp"+ii, ii);
	ext = this["cp"+ii];
	ext.onPress = function() {
		trace("onPress called");
	};
}

```

The MCs load into my scrollPane and everything fine, but they don’t respond to the onPress… Any idea why its not working?

---

<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:** [March 11, 2004, 2:19pm UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/2 "2004-03-11T14:19:22Z")

</div>

nope. If I do that the clips don’t even show up on the stage… Like I said, I have used this technique a million times in the past so I can’t understand why its not working right now…

---

<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:** [March 11, 2004, 2:29pm UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/3 "2004-03-11T14:29:21Z")

</div>

so you are assigning the onPress THEN loading something into that clip??

---

<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:** [March 11, 2004, 2:30pm UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/4 "2004-03-11T14:30:53Z")

</div>

No there was a bit more code in there. The loadMovie comes before the onPress:

```auto
this.createEmptyMovieClip("container", -1);
	container._visible = 0;
	for (ii=0; ii<xml_obj.firstChild.childNodes.length; ii++) {
		container.duplicateMovieClip("cp"+ii, ii);
		ext = this["cp"+ii];
		ext.loadMovie("http://localhost/ddd/img_create_thumb.php?im_path="+xml_obj.firstChild.childNodes[ii].childNodes[0]);
		ext._x = space_btn*(ii%num_wide);
		ext._y = yS;
		ext.onPress = function() {
			trace("onPress called");
		};

```

edit: The images loaded show up fine and in the correct places. But for some reason aren’t responding to the onPress…

---

<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:** [March 11, 2004, 2:44pm UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/5 "2004-03-11T14:44:39Z")

</div>

same difference. You have to make sure the loading is complete before you can assign the onPress. First rule of loadMovie for a movieclip: _all properties and methods of the movieclip are cleared when the new content is loaded into the clip_. This happens at the arrival of the new content, not the loadMovie call.

---

<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:** [March 11, 2004, 2:45pm UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/6 "2004-03-11T14:45:55Z")

</div>

ok i’ll give it a shot. thanks

---

<div class="post-metadata">

**Author:** ![pete\_zahut](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@pete\_zahut](https://forum.kirupa.com/u/pete_zahut)\
**Post date:** [March 28, 2006, 1:01pm UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/7 "2006-03-28T13:01:39Z")

</div>

So why isn’t this working?

[AS]_root[“word”+i].loadMovie ("word_" + arrayChoice\* + “.jpg”);

\_root[“word”+i].onEnterFrame = function() {  
trace(this.getBytesLoaded() + " / " + this.getBytesTotal());  
if(this.getBytesLoaded() \>= this.getBytesTotal()) {  
trace("\*\*\* load complete \*\*\*");

```
	_root["word"+i].onPress = function () {
		trace("pipo");
	}

	delete onEnterFrame;
} 

```

}[/AS]

I’ve put the onPress after the load is done…

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [March 28, 2006, 4:04pm UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/8 "2006-03-28T16:04:13Z")

</div>

use this.onPress =

---

<div class="post-metadata">

**Author:** ![rollwithit80](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@rollwithit80](https://forum.kirupa.com/u/rollwithit80)\
**Post date:** [March 28, 2006, 9:28pm UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/9 "2006-03-28T21:28:55Z")

</div>

Im having similar problems, when loading a movieClip into an empty container, I can’t access the onRelease event. For example:

```auto
 
t1.onRelease = function() {
 currentPic ='products/pro/mainImage.jpg';
 cMC.loadPic(currentPic);
};
 
MovieClip.prototype.loadPic = function(pic) {
 
 this.loadMovie(pic);
 this.onRelease = function(){
  this.unloadMovie(pic);
 // delete this._parent.onRelease;
 }
}

```

Thanks

Daniel

---

<div class="post-metadata">

**Author:** ![bombsledder](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bombsledder](https://forum.kirupa.com/u/bombsledder)\
**Post date:** [March 28, 2006, 9:40pm UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/10 "2006-03-28T21:40:29Z")

</div>

try

```auto

this.createEmptyMovieClip("container", -1);
for (ii=0; ii<xml_obj.firstChild.childNodes.length; ii++) {
               var ext:MovieClip= container.duplicateMovieClip("cp"+ii, ii);
                          trace(ext)
    ext.onPress = function() {
        trace("onPress called");
    };
}

```

i guess this won’t even help good thing someone bumped the thread now im looking at the dates lol…

---

<div class="post-metadata">

**Author:** ![pete\_zahut](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@pete\_zahut](https://forum.kirupa.com/u/pete_zahut)\
**Post date:** [March 29, 2006, 8:56am UTC](https://forum.kirupa.com/t/mc-onpress-not-working-w-createemptymc/45118/11 "2006-03-29T08:56:19Z")

</div>

I used a quick and dirty way to do it:  
Create an empty MC inside it, like imageholder or so, and load your movie into that imageholder. But keep the onPress on you original MC…

Senocular: this.onPress, didn’t work… (-:
