Dragging question

I have been playing with dragging as I know nothing about it.
I have my stage 500 x 500.

and following on from a tutorial I saw here on kirupa, I am loading a picture dynamically into flash, into a new movie clip which gets created, then making it draggable.
Here is the code I am using:


_root.createEmptyMovieClip("container", 1);
container.loadMovie("photo.jpg");
container._x = 0;
container._y = 0;
h = 500 - (container._height);
w = 500 - (conatiner._width);
_root.onMouseDown = function() {
    startDrag("container", false, 0, 0, w, h);
};
_root.onMouseUp = function() {
    stopDrag();
};

ok What I am trying to do is keep the ENTIRE picture within the stage at ALL times. However currently if you grab the edge you can drag the picture off the stage until just the edge of the picture is showing.
I thought (in my mind) this code would do this because “conatiner” would take the proportions of the picture… does it not?
I am obviously doing something wrong, what would be the code to do this?
thanks.

At the time you load, container (careful with the typos) still has a width and a height of 0. You must wait for the whole picture to load before you can do that.

pom :phil:

how do I do that?

onClipEventLoad?

You can’t use onClipEvent (load) because you have to use dynamic event handlers (dynamically created clip). Just set up an actionscript preloader. The code is all around here, but my favorite is here: http://actionscript-toolbox.com/samplemx_loadjpg.php

omg is looks like a total nightmareish hassle!! check my other drag question please!