14 Replies Latest reply on Sep 2, 2009 12:27 PM by kglad

    URLRequests and MovieClips

    mattk_ok

      I'm using AS3.

       

      Is there any chance of creating a function for an instance of an MC to run URLRequests for different items on different frames, or is the only route to create a new MC instance on each necessary frame and type out the request to pull a photo or.swf? Just wondering if I can cut down on the amount of keyframes I'll foreseeably have.

       

      Hopefully that made sense.

       

      Also, how do I run an animated preloader in the movie clip for when it's fetching and loading a photo.

       

      AND, how can I have the photo fade in (guessing somehow through brightness or alpha)? I know there's a lot being asked here. But with my naivete, I'm daunted trying to do these things inside a movie clip.

       

      If any can offer help, thanks, and let me know if I need to provide more context.

        • 1. Re: URLRequests and MovieClips
          kglad Adobe Community Professional & MVP

          urlrequests are unrelated to movieclips so i can't make any sense of your first question.

           

          use your loader's ProgressEvent.PROGRESS event to create a preloader.

           

          you can fade any display object by creating an alpha tween either in the timeline or with code.

          • 2. Re: URLRequests and MovieClips
            mattk_ok Level 1

            Well, here's my code:

             

            var loadRequest:URLRequest = new URLRequest("IMG_0064_2.jpg");

            var jpgLoader:Loader = new Loader();

            jpgLoader.load(loadRequest);

            holderMC_2.addChild(jpgLoader);

             

            I have an MC that houses a jpg on frame 2. On other frames, I'll have other MCs as frames for other images and maybe an .swf or two. I just didn't know if I'd need to create new keyframes and give the MCs different instance names, or if I could somehow circumvent that.

             

            And I'm just a bit confused how to use alpha tweens with an external file that is loaded. As well as a loader for that external image.

            • 3. Re: URLRequests and MovieClips
              kglad Adobe Community Professional & MVP

              why do you have a multi-frame setup?  what's the purpose?

              • 4. Re: URLRequests and MovieClips
                mattk_ok Level 1

                sorry, probably should've mentioned that:

                 

                I'm creating an interactive timeline. Each point jumps to a different frame that has different content on the stage.

                 

                The purpose of the movieclip as a frame was to load external files and keep the flash file size to a minimum.

                • 5. Re: URLRequests and MovieClips
                  kglad Adobe Community Professional & MVP

                  on frame one you can use the function below to load your images and add their loaders to their respective frame movieclips:

                   

                  function loadAndAddF(mc:MovieClip,urlS:String){

                  var ldr:Loader=new Loader();

                  var urlR:URLRequest=new URLRequest(urlS);

                  ldr.load(urlR);

                  mc.addChild(ldr);

                  }

                  • 6. Re: URLRequests and MovieClips
                    mattk_ok Level 1

                    Thanks. But due to my AS3 infancy, I'll have to mull that over for a bit.

                     

                    Any recommendations of alpha tweens in AS3 for externally loaded object? Is this something I can find a remedy for in a cookbook, or something?

                    • 7. Re: URLRequests and MovieClips
                      kglad Adobe Community Professional & MVP

                      assign your loader an alpha of zer0, check when loading is complete and then initiate an alpha tween.

                      • 8. Re: URLRequests and MovieClips
                        mattk_ok Level 1

                        any way to ensure that only the jpg's alpha is affected and not the loader/MC itself? I want the loader's border/frame to maintain a percentage of 100.

                         

                        Thanks.

                        • 9. Re: URLRequests and MovieClips
                          mattk_ok Level 1

                          KGlad, I don't know what the **** I'm doing.

                           

                          How do I alter the code to grab different photos for different frames? I have no idea.

                          Sorry that you have to spoon feed me.

                          • 10. Re: URLRequests and MovieClips
                            kglad Adobe Community Professional & MVP

                            if you only need to display one loaded image at any one time, add this to frame 1:

                             

                            var ldr:Loader = new Loader();

                            var t:Timer=new Timer(70,0);

                            t.addEventListener(TimerEvent.TIMER,fadeoutF);

                            var fadespeed:uint=.03;  // use whatever positive integer suits your needs

                             

                            function loadAndAddF(mc:MovieClip,urlS:String){

                            ldr.alpha=0;

                            var urlR:URLRequest=new URLRequest(urlS);

                            ldr.load(urlR);

                            mc.addChild(ldr);

                            ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompleteF);

                            }

                             

                            function loadCompleteF(e:Event){

                            t.start();

                            }

                             

                            function fadeoutF(e:Event){

                            ldr.alpha+=fadespeed;

                            if(ldr.alpha>=1){

                            ldr.alpha=1;

                            t.stop();

                            }

                            }

                             

                            // **************************************

                            /*

                            then on each frame where you want to load an image into a frame movieclip use something like:

                            */

                            // **************************************

                             

                            loadAndAddF(frameMC,"pics/image22.jpg");

                             

                            // where frameMC is the name of your frame movieclip and you want to load image22.jpg that's in the pics folder.

                            • 11. Re: URLRequests and MovieClips
                              mattk_ok Level 1

                              This all looks beautiful.

                               

                              Still a minute problem: there's no alpha change occurring. I imported a package for the timer, do I need to do something for the alpha tween? I already imported easing and Tween.

                               

                              But the Timer is cool; I didn't know how to do that, so there's a lesson learned.

                               

                              Thanks for all the attention and help.

                               

                              Either way, your code does cut down the amount of code needed to load photos on other frames. This alpha just won't work, though.

                              • 12. Re: URLRequests and MovieClips
                                kglad Adobe Community Professional & MVP

                                oops, my error:

                                 


                                 

                                var ldr:Loader = new Loader();

                                var t:Timer=new Timer(70,0);

                                t.addEventListener(TimerEvent.TIMER,fadeoutF);

                                var fadespeed:Number=.03;  // use whatever number suits your needs

                                 

                                function loadAndAddF(mc:MovieClip,urlS:String){

                                ldr.alpha=0;

                                var urlR:URLRequest=new URLRequest(urlS);

                                ldr.load(urlR);

                                mc.addChild(ldr);

                                ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompleteF);

                                }

                                 

                                function loadCompleteF(e:Event){

                                t.start();

                                }

                                 

                                function fadeoutF(e:Event){

                                ldr.alpha+=fadespeed;

                                if(ldr.alpha>=1){

                                ldr.alpha=1;

                                t.stop();

                                }

                                }

                                 

                                // **************************************

                                /*

                                then on each frame where you want to load an image into a frame movieclip use something like:

                                */

                                // **************************************

                                 

                                loadAndAddF(frameMC,"pics/image22.jpg");

                                 

                                // where frameMC is the name of your frame movieclip and you want to load image22.jpg that's in the pics folder.

                                • 13. Re: URLRequests and MovieClips
                                  mattk_ok Level 1

                                  Ah! Beautiful. Thanks so much. I think I learned some Flash fundamentals in the process.

                                   

                                  Also, using this line of thought, could I create a preloader, make it a variable and place it in the load function?

                                  • 14. Re: URLRequests and MovieClips
                                    kglad Adobe Community Professional & MVP

                                    you're welcome.  and yes, you can use the progressevent to display the preload progress of your loading images.