all groups > flash actionscript > august 2006 >
You're in the

flash actionscript

group:

What's the difference


Re: What's the difference David Stiller
8/13/2006 5:38:04 PM
flash actionscript: Tim,

[quoted text, click to view]

createEmptyMovieCip() is a method, not a function. Conceptually,
they're the same thing, but methods belong to a class, while functions are
"free floating" and "just are." In your original code, you're using the
global "this" property to reference an object -- presumably, the main
timeline, which is a movie clip. Because it's a movie clip, it is an
instance of the MovieClip class, which means it has all the functionality
defined by the MovieClip class, including the
MovieClip.createEmptyMovieClip() method.

Without the "this" or some other movie clip reference, it may be that
your method simply isn't firing. I notice you *are* using "this" in the
MovieClip.getNextHighestDepth() method later in that same line.

I made a test real quick -- nothing more than the following in a blank
FLA:

createEmptyMovieClip("a", 0);

.... and that did, indeed, create a new MovieClip instance, named "a" (as
verified in the Debugger panel). Do to this result, I'm not convinced your
lack of "this" is the cause, but it certainly is a difference between your
two attemps.

Another thing ...

[quoted text, click to view]

You may have problems with that next part because of the fact that
you're loading external content. While 1.jpg may load instantly on your own
machine, it may not when requested from a server. The problem with these
lines is that *while* 1.jpg is being loaded, the remaining ActionScript is
executed, without waiting until the JPG loaded completely. Depending on
what you're trying to do, this could lead you toward unexpected or erroneous
results.

The solution is to wait until your external content has loaded
completely.

http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."

What's the difference timothytrice
8/13/2006 7:53:07 PM
Besides the fact that one works and the other does not (the for loop does not
display the images), what in the world is the difference between these two
scripts?

Works:
[CODE]
this.createEmptyMovieClip("logo_mc", this.getNextHighestDepth());
logo_mc.loadMovie("1.jpg");
logo_mc._x = 20;
logo_mc._y = 20;
this.createEmptyMovieClip("logo_mc1", this.getNextHighestDepth());
logo_mc1.loadMovie("2.jpg");
logo_mc1._x = 200;
logo_mc1._y = 20;
this.createEmptyMovieClip("logo_mc2", this.getNextHighestDepth());
logo_mc2.loadMovie("3.jpg");
logo_mc2._x = 380;
logo_mc2._y = 20;
[/CODE]

Does not work:
[CODE]
for (i=1;i<=3;i++) {
switch (i) {
case 1:
createEmptyMovieClip("logo_mc", this.getNextHighestDepth());
logo_mc.loadMovie("1.jpg");
logo_mc._x = 20;
logo_mc._y = 20;
break;
case 2:
createEmptyMovieClip("logo_mc1", this.getNextHighestDepth());
logo_mc1.loadMovie("2.jpg");
logo_mc1._x = 200;
logo_mc1._y = 20;
break;
case 3:
createEmptyMovieClip("logo_mc2", this.getNextHighestDepth());
logo_mc2.loadMovie("3.jpg");
logo_mc2._x = 380;
logo_mc2._y = 20;
break;
}
}
[/CODE]

Would really appreciate any suggestions as it's really killing my program.

Tim:mad;
AddThis Social Bookmark Button