Skip to main content
Participant
May 4, 2006
Answered

Loading JPG into a specific layer

I'm a Flash beginner, so I apologize if this question is silly...

I created a movie clip with several layers. Some of the layers have images that I dragged onto the stage from my library of symbols.

My top layer "Actions" contains all my ActionScript code. in this layer I am creating an empty movie clip using the createEmptyMovieClip() method and then attempting to load a JPG using the loadMovie() method. I want the JPG to appear "behind" other images in the movie clip (i.e a lower layer). I'm assuming that I should accomplish this by passing a certain depth in the createEmptyMovieClip() method.

However, no matter what value I seem to pass to createEmptyMovieClip(), the JPG appears "in front" of all other layers. otherwise it's working fine.

Although there is a lot of doco about the methods, i can find very little description about how "depth" works. My understanding is that a higher depth value means the movie clip will be created on a higher layer (more "in front"), but I can't seem to use this value to affect where the image ends up when loaded.

Any assistance would be greatly appreciated. I have developed a work around, but I'd really liked to understand how this is supposed to work.

Thanks so much!

Steve

This topic is closed to new replies. Start a new post to keep the conversation going.
shyawayCorrect answer
Participating Frequently
May 4, 2006
the mc you placed on stage actually have negative value for depth in thousands.
try the getDepth and see for yourself.
there's a depth manager class that allow you to manage.
however, a quick and easy way to manage the depth with using another class...

in your layer, put an empty movie clip in there, you have to create an empty one like mcBlank
then name the instance jpg_mc
place is in the layer you want,
and at run time, you can use loadMovie("mypic.jpg",jpg_mc);

7 replies

Participant
May 4, 2006
Shyaway, David and Tim,

Thanks a ton guys! Especially David for taking the time to explain some of the nuts and bolts.

Although I don't totally understand what a depth is now (I'll read up on it though), I understand that this doesn't simply correspond to the layer on the timeline like I originally thought.

It seems that the best way to handle this will be to "manually" add a movie clip and then load it there.

Thanks again
Translate
Inspiring
May 4, 2006
> the easiest method I know of is to place a .jpg in a movie
> and publish it as a .swf then the loadmovie command will
> work.

Both the loadMovie() function and the MovieClip.loadMovie() method load
JPGs just fine. Since the release of Flash 8, it's even possible to
load GIFs and PNGs, too.

>> My top layer "Actions" contains all my ActionScript code.
>> in this layer I am creating an empty movie clip using the
>> createEmptyMovieClip() method and then attempting to
>> load a JPG using the loadMovie() method.

As it turns out, there is no ActionScript equivalent to layers. There
are depths, which *roughly* correlate to layers -- depths pertain to a given
timeline, but it doesn't get deeper than that.

>> I want the JPG to appear "behind" other images in the
>> movie clip (i.e a lower layer). I'm assuming that I should
>> accomplish this by passing a certain depth in the
>> createEmptyMovieClip() method.

Anything you load or create dynamically will appear above assets you
drag to the Stage by hand. You could arrange your manual content into one
movie clip and load your JPG into another, then invoke
MovieClip.swapDepths() to swap their depths.

>> My understanding is that a higher depth value means the
>> movie clip will be created on a higher layer (more "in
>> front"), but I can't seem to use this value to affect where
>> the image ends up when loaded.

Yeah ... it really does seem like layers *should* correspond to depths,
but it just doesn't work that way. I *believe* that layers are located at a
reserved depth (possibly negative numbers).


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


Translate
Participating Frequently
May 4, 2006
Your dynamically created movieclips will appear ontop of eveything on the stage unless you use a specific negative depth. I can't rmemeber the number off the top of my head but it exists. A little more subtle way to do this is to place an empty movieclip on a layer that is below all the elements you want your image to be behind. Then just load your JPG into that movieclip instaed of creating an empty clip dynamically.

Tim
Translate
shyawayCorrect answer
Participating Frequently
May 4, 2006
the mc you placed on stage actually have negative value for depth in thousands.
try the getDepth and see for yourself.
there's a depth manager class that allow you to manage.
however, a quick and easy way to manage the depth with using another class...

in your layer, put an empty movie clip in there, you have to create an empty one like mcBlank
then name the instance jpg_mc
place is in the layer you want,
and at run time, you can use loadMovie("mypic.jpg",jpg_mc);
Translate
Inspiring
May 4, 2006
one more thing ...if you make the movie that the .jpg is placed the same size as the movie it is loading into, then you can place the .jpg where you want it to appear and it will register that position when loaded.
Translate
Inspiring
May 4, 2006
the easiest method I know of is to place a .jpg in a movie and publish it as a .swf then the loadmovie command will work.
Translate
Participant
May 4, 2006
Thanks for the advice nice multimedia. However, I don't think that creating an SWF for each JPG that I want to load will be feasible since I have many of them and will be changing them frequently via an XML control file. I'm doing this so that I can change the images loaded without having to go into Flash and re-publish, so having to generate an SWF file everytime I have a new image would probably defeat that purpose. Thanks again though for the quick response!
Translate