PDA

View Full Version : My loadJPG function doesn't work with "this"



3dron
November 10th, 2002, 03:23 AM
This works:

_global.loadJPG = function (name, mc, x, y) {
createEmptyMovieClip(mc, m++);
_root.[mc].moveTo( x, y);
loadMovie (name, mc);
}

This doesn't work:

_global.loadJPG = function (name, mc, x, y) {
this.createEmptyMovieClip(mc, m++);
this[mc].moveTo( x, y);
loadMovie (name, mc);
}

Why doesn't "this" work? I need it because this function is not always called from the _root.

Ron

pom
November 10th, 2002, 05:06 AM
Try this:
_global.loadJPG = function (name, mc, x, y) {
this.createEmptyMovieClip(mc, m++);
this[mc].moveTo( x, y);
this[mc].loadMovie (name);
}Any help?

pom :cowboy:

3dron
November 10th, 2002, 12:41 PM
I tried this also, and no luck.

It seems that no empty clip is being created in the first place.

Without the "this" it works.

Help

ROn

pom
November 10th, 2002, 01:08 PM
Well, I'm not sure, but I think that _global is an object. So maybe you're creating a clip in that object, which may not be possible. I'm just guessing here.

Did you try the function without _global in front?

pom :)

sbeener
November 10th, 2002, 07:20 PM
ily's on the money.

_global is not a movie clip and thus doesn't have the methods that are available to movieclips. try writing it as a movieclip method.


MovieClip.prototype.loadJPG = function (name, mc, x, y) {
var clip = this.createEmptyMovieClip(mc, m++);
clip.moveTo( x, y);
clip.loadMovie (name);
}

3dron
November 11th, 2002, 12:54 AM
Great guys this makes sense, and works. Except for the moveTo. It doesn't seem to take the positioning.


clip.moveTo( x, y);

Doesn't work


clip._x = x; clip._y = y;

This does?

I guess I can live with. But why?

Ron

sbeener
November 11th, 2002, 03:57 AM
moveTo is part of the drawing api, not a method to change the x,y of a movieclip.

but given the wording, you could be excused for the mistake. ; )