Skip to main content
Michael Lunsford
Inspiring
September 10, 2008
Answered

dynamic image load with MovieClipLoader

  • September 10, 2008
  • 14 replies
  • 1119 views
I'm trying to load five images from five URLs. If I use the documentation exactly as is, it works fine. Problem is, I don't want to createEmptyMovieClip, I want to use an existing one that's tucked inside a movie instance. Also, the images coming in are of unknown size, but have a standard 4:3 size ratio. I'd also like to scale them down to 180x120 after they arrive. Any help would be greatly appreciated.

The code below only loads one image (which isn't working). I will eventually need it to load five different images.

This topic has been closed for replies.
Correct answer Rothrock
Hey we've all been there with messing up the names of variables and stuff and such. So hopefully you are learning how to use the traces in specific spots to find the names of things.

What that is telling you is that at the time that code executes there isn't a movieclip with that name. I downloaded your fla and sure enough the code is on Frame 1, but the clip doesn't exist until Frame 2. You need to move the stage placed clips to frame 1. And it should work.

14 replies

Michael Lunsford
Inspiring
September 10, 2008
yeah, I messed up the variable name -- it was supposed to be PhotoURL1, not just Photo1. That fixed it.
my final trace call now says loading http://www.example.com/images/08180700_0223280.jpg to undefined

which pretty much sums up the problem: the exact path to the movie remains elusive. Your trace("The target is: "+Prop1.image); also verifies this.
The target is: undefined

I did change the name of image1 to image (as you suggested). So, the next step is figuring out what the name of that movie clip is. I'm probably doing something stupid. If you'd care to take a gander:
http://www.uncommonname.com/vidframeTDA8.fla

The only one I've messed with is the first one (the other four have static, embedded images) since if I can't get one to work, what's the point of working on all five?

Inspiring
September 10, 2008
I'm not following what you have done. Repost and attach your code as it is now.

It is looking like you have an instance on the stage that you haven't given a name. You can't count on it being called instance7 since that is assigned by Flash. So instead you should be sure to give it a name.

Also I don't think you are quite following the help files layout. Normally you create an object:

var myListener:Object=new Object();

And then you add the events to that:

myListener.onLoadInit=function(mc:MovieClip){
// stuff you want to do
}

Then you add the object as a listener to your MCL.

mcLoader.addListener(myListener);

And finally you load you content:

mcLoader.loadClip(sourceURL,someClip);

Just as a note, I probably wouldn't have a separate function like loadSomeImage reference a different LoadVars object. Kinda messy and what if latter you might want to use the function to load something else? I would do this:

function loadSomeImage(source:String,target:MovieClip){
mcLoader.loadClip(source,target);
}

And then in your LoadVars onLoad event handler

loadSomeImage(this.PhotoURL1,pathToImage);
Michael Lunsford
Inspiring
September 10, 2008
Okay, I named the movie the image1 movie resides inside of to "Prop1". putting an on(load) { trace(this) } returns nothing, though. So, the below code shows the evolution so far.
OH, FYI, the following output comes in:
vars loaded
loading undefined to undefined
and the document stays on frame1. the trace inside onLoadStart never fires, so I can only assume the loading process never begins.
Michael Lunsford
Inspiring
September 10, 2008
That's good news. I'm still struggling with it, though. I changed from Start to Init (which works as coded above), commented the createEmptyMovieClip and changed the loader to mcLoader.loadClip(lv.PhotoURL1, image1); but it gets stuck somewhere between load_some_images() and the onLoadStart() and just sits there.

I also tried attaching a on(load) { trace(this); } to the image1 movie clip I want this image loaded into. It returns "_level0.instance7.image1" If I try that as the target, it sticks again. Any idea what the right semantics are?
Inspiring
September 10, 2008
Then for the second argument in the loadClip don't use the container, use the path to the clip that you want to load it into. (Of course you can also lose the line where you create the empty movieclip, or you could just pass a reference to the path of your clip to the container variable and keep using it in your loadClip(). The choice is yours.)

And you have two problems with setting the dimensions. This is AS2 and in AS2 the properties you want are _width and _height. The second problem is that you can't set the _width and _height at the start of the load. You are using the wrong event. You must wait until the content is loaded and then you can set those.

The event you want is the onLoadInit event. At that point you will be able to set properties.