10 Replies Latest reply on Jul 8, 2009 1:26 PM by kglad

    loading multiple jpeg files

    jbordersfl

      i'm making a simple portfolio site, and bringing in a series of jpeg files using a 'for' loop and the Loader class.

       

      once all the files are loaded in, i'd like to just be able to add, remove, tween, etc...  the items from the stage as need-be by using instance names, such as movie clips or Sprites.

       

      but for some reason, i cannot seem to figure out how to have each image, as its loaded in, be separately accessable to me after the loop has completed.

       

      any ideas on this would be great. i've tried a hundred things & nothing seems to work.

       

      thanks!

      jamie

        • 1. Re: loading multiple jpeg files
          kglad Adobe Community Professional & MVP

          assuming you're using as3, you should be using different loaders for each image and you can assign a name property for each loader and use that to retreive a reference to the loader using the getChildByName() applied to the loaders' parent.

          1 person found this helpful
          • 3. Re: loading multiple jpeg files
            jbordersfl Level 1

            ok, so thanks for the tip, i figured out how to add a specified item to the stage with this:

             

            import flash.display.Sprite;
            import flash.display.MovieClip;
            import flash.display.Loader;
            import flash.display.DisplayObject;

             

            var container:MovieClip = new MovieClip();

             

            for (var i:uint = 1; i < 4; i++) {

             

               var req:URLRequest = new URLRequest("/images/bro" + i + ".jpg");
               var loader:Loader = new Loader();

             

            loader.load(req); 
            loader.name = "brochure" + i;
            trace(loader.name);

             

            container.addChild(loader);

             

            }

             

            addChild(container.getChildByName("brochure1"));

             

             

            swapping out brochure1, brochure2, brochure 3 in the last line of code, i can display the items i want to display.

             

            now comes what i hope is a simple question... how can i change the properties of that item?

             

            brochure1.alpha = .5;

             

            this gives me an error for example.  how can i control this now that it's on the stage?

            • 4. Re: loading multiple jpeg files
              kglad Adobe Community Professional & MVP

              use:

               

               

              container.getChildByName("brochure1").alpha=.5

              1 person found this helpful
              • 5. Re: loading multiple jpeg files
                jbordersfl Level 1

                that seemed like the logical way to it, but it gives me the following error:

                 

                TypeError: Error #1009: Cannot access a property or method of a null object reference.
                    at Untitled_fla::MainTimeline/frame1()

                 

                 

                here's the code with that line at bottom:

                 

                import flash.display.Sprite;
                import flash.display.MovieClip;
                import flash.display.Loader;
                import flash.display.DisplayObject;

                 

                var container:MovieClip = new MovieClip();

                 

                for (var i:uint = 1; i < 4; i++) {

                 

                   var req:URLRequest = new URLRequest("/images/bro" + i + ".jpg");
                   var loader:Loader = new Loader();

                 

                loader.load(req);
                loader.name = "brochure" + i;
                trace(loader.name);

                 

                container.addChild(loader);

                 

                }

                 

                addChild(container.getChildByName("brochure2"));

                 

                container.getChildByName("brochure2").alpha = .5;

                • 6. Re: loading multiple jpeg files
                  kglad Adobe Community Professional & MVP

                  jbordersfl wrote:

                   

                  that seemed like the logical way to it, but it gives me the following error:

                   

                  TypeError: Error #1009: Cannot access a property or method of a null object reference.
                      at Untitled_fla::MainTimeline/frame1()

                   

                   

                  here's the code with that line at bottom:

                   

                  import flash.display.Sprite;
                  import flash.display.MovieClip;
                  import flash.display.Loader;
                  import flash.display.DisplayObject;

                   

                  var container:MovieClip = new MovieClip();

                   

                  for (var i:uint = 1; i < 4; i++) {

                   

                     var req:URLRequest = new URLRequest("/images/bro" + i + ".jpg");
                     var loader:Loader = new Loader();

                   

                  loader.load(req);
                  loader.name = "brochure" + i;
                  trace(loader.name);

                   

                  container.addChild(loader);

                   

                  }

                   

                  //addChild(container.getChildByName("brochure2"));

                   

                  container.getChildByName("brochure2").alpha = .5;

                  • 7. Re: loading multiple jpeg files
                    jbordersfl Level 1

                    kglad wrote:

                     

                    jbordersfl wrote:

                     

                    that seemed like the logical way to it, but it gives me the following error:

                     

                    TypeError: Error #1009: Cannot access a property or method of a null object reference.
                        at Untitled_fla::MainTimeline/frame1()

                     

                     

                    here's the code with that line at bottom:

                     

                    import flash.display.Sprite;
                    import flash.display.MovieClip;
                    import flash.display.Loader;
                    import flash.display.DisplayObject;

                     

                    var container:MovieClip = new MovieClip();

                     

                    for (var i:uint = 1; i < 4; i++) {

                     

                       var req:URLRequest = new URLRequest("/images/bro" + i + ".jpg");
                       var loader:Loader = new Loader();

                     

                    loader.load(req);
                    loader.name = "brochure" + i;
                    trace(loader.name);

                     

                    container.addChild(loader);

                     

                    }

                     


                    container.getChildByName("brochure2").alpha = .5;

                    addChild(container.getChildByName("brochure2"));

                     

                    ok, the stage was still blank though, but by moving addChild AFTER the alpha property designation, then it worked.

                     

                    i was under the assumption you could add the child, then designate properties but apparently not.  ??

                     

                    thank you for your replies.

                    • 8. Re: loading multiple jpeg files
                      kglad Adobe Community Professional & MVP

                      your last line of code is re-parenting brochure2 from container to the current timeline.  you should omit that line of code.

                       

                      and you're not going to see any of the loaded images until you add container to the display list.

                      • 9. Re: loading multiple jpeg files
                        jbordersfl Level 1

                        kglad wrote:

                         

                        your last line of code is re-parenting brochure2 from container to the current timeline.  you should omit that line of code.

                         

                        and you're not going to see any of the loaded images until you add container to the display list.

                         

                         

                        ok, but if i:

                         

                        addChild(container);

                         

                        only "brochure3" is visible, because it adds all 3 (brochure1, brochure2, brochure3)  to the stage, with brochure3 at the top.

                         

                        this is the main problem i've been having all along, is how do i individually add, remove, change properties on each one of these items?

                        • 10. Re: loading multiple jpeg files
                          kglad Adobe Community Professional & MVP

                          if you want them all visible at once, don't stack them one over the other.  use their x,y properties to display them.

                           

                          if you want them stacked use and you want to bring brochure1 to the top use:

                           

                          container.addChild(container.getChildByName("brochure1"));