Groups | Blog | Home
all groups > flash actionscript > september 2004 >

flash actionscript : LoadMovie and createEmptyMovieClip()



Patrick Bay
9/15/2004 6:04:04 PM
Hi,

You have to wait until the image is fully loaded before attaching
code to it, otherwise it will be destroyed.

Do it like this:

this.onEnterFrame=function() {
loaded=pic.getBytesLoaded();
total=pic.getBytesTotal();
if ((loaded==total) && (total>0)) {
pic.onRelease = function() { trace("clicked");}
this.onEnterFrame=null;
}
}

Regards,
Patrick

-----------------------------------------------------
www.baynewmedia.com

IRC (www.dal.net) -> #baynewmedia
-----------------------------------------------------



[quoted text, click to view]
thedanster
9/15/2004 10:01:51 PM
I am doing a
createEmptyMovieClip("pic",100)

then loading a jpeg into the newly created movieclip
pic.LoadMovie("image.jpg");

The image loads ok, but then I want to add an onRelease event handler like
pic.onRelease = function() { trace("clicked");}

I never see the trace.

What am I overlooking?
tia
DAN
thedanster
9/15/2004 10:29:16 PM
Thanks for the reply.

I have tried your approach and I still do not get the clicks trace() to show.
On the onEnterFrame I am doing a trace that shows the image is loaded.

I will try some other possibilities

DAN
asidfree
12/19/2005 5:48:34 PM
You have to wait until the image is fully loaded before attaching
code to it, otherwise it will be destroyed.
Hello. I am working with a similar scenario where I am creating an empty
movie clip, loading a movie into it, and then trying to get the _width and
_height of the movie clip. The problem that I am encountering is exactly what
I think you are saying, and I had suspected as much, but I haven't been able to
resolve this problem.

The movie loads into the emptyMovieClip and displays, but there is no _width
or _height for it (you can see where I checked it with a trace). The values
for the width and height have returned as undefined. Attached is the code that
I'm working with, and as always, I greatly appreciate all the help that is
offered.

~Dave



_root.createEmptyMovieClip("map", 2); //create a movie clip for the map

var ml, mr, mt, mb;

//load map variables
map.onLoad = function() {
ml = map._x;
mr = parseInt(map._x + map._width);
mt = map._y;
mb = parseInt(map._y + map._height);
trace('got here'); //it never get's here
}

map.loadMovie("images/Map.swf"); //load in the map

//print out the map dimensions
trace("map l: " + ml); //these all return as undefined
trace("map r: " + mr);
trace("map t: " + mt);
trace("map b: " + mb);
AddThis Social Bookmark Button