17 Replies Latest reply on Sep 16, 2008 11:52 AM by Michael Lunsford

    dynamic image load with MovieClipLoader

    Michael Lunsford
      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.

        • 1. Re: dynamic image load with MovieClipLoader
          Rothrock Level 5
          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.
          • 2. Re: dynamic image load with MovieClipLoader
            Michael Lunsford Level 1
            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?
            • 3. Re: dynamic image load with MovieClipLoader
              Rothrock Level 5
              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);
              • 4. Re: dynamic image load with MovieClipLoader
                Michael Lunsford Level 1
                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.
                • 5. Re: dynamic image load with MovieClipLoader
                  Rothrock Level 5
                  Hmmm. Okay.

                  I'm not sure about your LV. So let's do some checking in there.

                  First inside of the lv.onLoad handler the scope will be your lv instance of the LoadVars class. So you only need to use this to refer to the lv instance.

                  Let's check what it is getting. So put this code before the call to the function.

                  for(var a in this){
                  trace(a+" is "+this[a]);
                  }

                  What does the trace say now?

                  I'm guessing the problem with the target you are trying to load into is that the path isn't quite right.

                  What if on the line after the stop() you put this?

                  trace("The target is: "+Prop1.image1);

                  What trace do you get there?

                  Also here is a design idea for you. If Prop1 is going to hold photo 1 and Prop2 is going to hold photo 2, then why do you need the image1, image2, etc. instances? That just makes it harder to reference them. Instead if every Prop has an image why not name the instance inside just "image"? so then the path would be Prop1.image, Prop2.image, etc. A lot easier.
                  • 6. Re: dynamic image load with MovieClipLoader
                    Michael Lunsford Level 1
                    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?

                    • 7. Re: dynamic image load with MovieClipLoader
                      Rothrock Level 5
                      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.
                      • 8. Re: dynamic image load with MovieClipLoader
                        Michael Lunsford Level 1
                        Okay, I did what you said -- moved all the movie containers to the first frame. The AS works great now.

                        New problem. Now I have five movie containers with text and images all on the first frame. My static text and images respond to making the container movie 0% alpha, but the dynamic text doesn't listen. Now what?
                        • 9. dynamic image load with MovieClipLoader
                          Michael Lunsford Level 1
                          Okay, a few more challenges: The images all load, but the second go-round all but the last image loaded disappear. Do I need to build a separate loader for each image?

                          Also, since all the movie instances are in the first frame before the text variables load, the text is empty. Once the movie makes a complete loop, the text appears.
                          • 10. Re: dynamic image load with MovieClipLoader
                            Rothrock Level 5
                            Dynamic text that doesn't have embedded fonts won't respond to tweening, alpha, etc. So you need to embed the font(s). There are a couple of ways to do this depending upon what you are doing. But most likely you can just select the text field and click the font button on the properties panel and select embed. Also I would recommend that you use _visible=false instead of alpha for this effect.

                            I'm not sure what the second go-round is. Can you explain that a bit better? You should be able to use the same loader, so I'm not quite sure what is going on. Again, look for some helpful places to put some traces and see if you can figure out what is going on. Remember that generally Flash does what we tell it, not what we want! So if you can find the places where you are telling it to do things you can figure out what is happening.

                            Also I'm not clear on what is going on with the variables and text. Generally I would recommend against using the variable property of text fields. That is a leftover from the Flash 5 days when you couldn't work directly with dynamic text fields. Instead give the fields instance names and then assign the text with the text property.

                            myTextField.text="some value in here";
                            myTextField2.text=someStringVariable;




                            • 11. Re: dynamic image load with MovieClipLoader
                              Michael Lunsford Level 1
                              Oh, sorry. By "the second go around" I mean the whole thing loops. At the end of the movie I have a script that says gotoAndPlay(2) that brings you back to the first frame that doesn't load anything. If I do this, it will have only the last image loaded.

                              Also, I've managed to hack a fix by moving the image loads to frame 2. But this just reloads the images again (and adds a slight pause to the movie).
                              • 12. Re: dynamic image load with MovieClipLoader
                                Rothrock Level 5
                                Are you doing any depth swapping? That is what it sounds like. Other than that I wouldn't know.

                                I would probably design this whole thing very differently from what I briefly saw in you FLA. So it is hard to know what to suggest at this point. For example I almost never have the main timeline loop. My main timelines are either one frame with some code or maybe 20 or 30 frames with keyframes and labels at 1 and 10. The labels would be something like "init" and "content". The init label would have some code to load some variables and assets and then it would gotoAndStop("content");
                                • 13. Re: dynamic image load with MovieClipLoader
                                  Michael Lunsford Level 1
                                  It's apparently the best practices stuff that's coming around to bite me. I'll rework it today and let you know how it goes.
                                  • 14. Re: dynamic image load with MovieClipLoader
                                    Rothrock Level 5
                                    While you are at it, you might want to have only one of these pre-made templates and set it to export for actionscript. Then you can use attachMovie to attach as many of them as you need after the variables load. That way you might have 5 some day, but some other day you might have 8 or 3 or whatever. Just a thought.

                                    It is hard to give advice on exactly how to do these things because everybody's requirments are different and everybody's thought process is different. You are making progress and there wasn't anything deeply flawed with your original idea. Just a few little areas where it can be worked this way or that way a bit easier.
                                    • 15. Re: dynamic image load with MovieClipLoader
                                      Michael Lunsford Level 1
                                      Well, I have it almost ready to go. It's mostly a crazy hack, but it works in test mode.

                                      Two problems, one major, one not so major:

                                      1. "Flash player has stopped a potentially unsafe operation." The LoadVars is calling an external URL. There's nothing I can do to localize the URL, as this flash file is running on an ad server that I don't have access to. This is preventing the variables from loading, and breaking the whole file. Any hacks to get around this wonderful "feature"?

                                      2. The issue previously mentioned about only the last loaded image remaining after the movie loops. Basically, the movie holds on frame 2 until until all five images load. It scrolls through the five images. at the end, it reaches a gotoAndPlay(3) that loops back to frame 3. The first four images are missing, but the last one is in place. I've "fixed" this issue by going back to frame 2, which reloads all five images. The big part of this problem is it can take 15 to 30 seconds to reload the images.

                                      the latest revision is here:
                                      http://www.uncommonname.com/vidframeTDA8b.fla
                                      • 16. Re: dynamic image load with MovieClipLoader
                                        Rothrock Level 5
                                        Not sure on the first one. I haven't done cross domain scripting. Are you seeing this problem in the test publish environment or have you actually put it on your server to test it? I think that might fix it. Otherwise you'll need to look into cross domain. I think that the server needs an xml file at the root that allows your domain to access it. I'm sure that can be worked out.

                                        As for the next I'm not really sure. but you could put some kind of conditional that checks if they have already been loaded and if so don't load them again. It is strange that it takes so long to reload them. Generally they sould be in the browser cache and reloading should be almost instantaneous.

                                        Why are you looping at all? Are you doing depth swapping?
                                        • 17. Re: dynamic image load with MovieClipLoader
                                          Michael Lunsford Level 1
                                          Wow, well, I got really lucky and the ad serving software can remotely deliver the ad, so I put it on the same "remote" server that the database script resides. Presto, problem one is gone.

                                          An added benefit to having it actually online and working is the browser is caching the images, so it only flickers on the loading page before continuing.

                                          Looping because I built the ad using techniques from flash 5 or so where the entire movie is on the main timeline. I need to take a flash class, or get a book on best practices because I really don't get how to do it any other way.

                                          Anyway, Thanks Rothrock, you saved me big time on this one. That neglected name on the middle container movie was the big thing that held me up. The rest of this stuff was just hacking until I got it figured out.

                                          Thanks!