Trouble accessing newly created MC

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 !

Welcome to kirupa forum, daw0lverine! :stuck_out_tongue:

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. :slight_smile:

// 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");

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

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

  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? :wink:

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. :-*

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

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

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");

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 ?

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. :slight_smile:

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

Thank you very much :DD

You’re welcome. :beam: