13 Replies Latest reply on May 8, 2007 9:14 AM by nelly_1

    How to Load Multiple PNGs in AS3

    Rothrock Level 5
      I'm at a bit of a loss as to how I can load multiple external PNG files. It seems that the classes used to display content are instantiated with the new Constructor();

      So how do I give them names like, sprite1, sprite2, etc.

      For example the below code. I would like to end up with something like clip1, clip2, etc. so that I can drag them around or such.

      Also, I know that I can just add a Loader instance to the DisplayObjects with addChild(myLoader) but is that how I should do it? Or should these be converted to some other class? Sprite? MovieClip?
        • 1. How to Load Multiple PNGs in AS3
          tanenbaumm
          As I understand it, your Loader is essentially a proxy for the image being loaded. So if you dynamically set the name of your Loader (for example, "image_"+count), you could use that variable later to move the sprites around. (I admit I haven't actually tried this yet, but I believe it'll work)
          • 2. Re: How to Load Multiple PNGs in AS3
            Rothrock Level 5
            Thanks for the help, but I'm just not getting it. So I'm still at the same place I was before. A loader instance is create by new Loader(), right. So how do I do this?

            var myLoader+count:Loader=new Loader()

            That doesn't work! So perhaps the real question is how do I create dynamic names for just about any of the new classes?

            var mySprite+count:Sprite=new Sprite();
            var myDO+count:DisplayObject=new DisplayObject();

            And how do I even create a new MovieClip? The documentation is awful!
            • 3. Re: How to Load Multiple PNGs in AS3
              pajaroplus Level 1
              i think you need arrays.

              push every loader into an array. this way you keep them all accessible.
              • 4. Re: How to Load Multiple PNGs in AS3
                pajaroplus Level 1
                i think you need arrays.

                push every loader into an array. this way you keep them all accessible.
                • 5. How to Load Multiple PNGs in AS3
                  tanenbaumm Level 1
                  I'm thinking something like this:
                  • 6. Re: How to Load Multiple PNGs in AS3
                    tanenbaumm Level 1
                    Oops.
                    function startLoad(xiNum:Number){

                    That Number should really be a uint. But whatever.
                    • 7. Re: How to Load Multiple PNGs in AS3
                      Rothrock Level 5
                      Thanks. Next chance I get I'm going to try that out!
                      • 8. Re: How to Load Multiple PNGs in AS3
                        tanenbaumm Level 1
                        Took me a few minutes fiddling, but here it is:
                        • 9. Re: How to Load Multiple PNGs in AS3
                          nelly_1
                          you don`t really need an array for the Loaders -I`ve added a onPress just so you can see how to reference
                          • 10. Re: How to Load Multiple PNGs in AS3
                            Rothrock Level 5
                            I'm so grateful to you both. This is giving me a lot to think about.

                            So nelly 1 where in the world does the name property of a Loader instance come from? It isn't in the documentation. I assume it is inherited from one of the super classes?

                            BTW, this is what I'm talking about. So supposed I had noticed that in the list of methods and properties that came up for voLoader that name was a choice. If I then selected that and done an F1 for help on it I would get this entry:

                            name property
                            public var name:String
                            Language version: ActionScript 3.0
                            Player version: Flash Player 9
                            Contains the name of the Error object. By default, the value of this property is "Error".

                            I'm pretty sure that Loader doesn't inherit name from the Error class, and even if it does, that doesn't really help me learn how to use it, now does it! Formerly the answer to so many questions was, "Look it up in the help files." But now they really are almost useless.

                            Can I impress on you for one more tweek? I'm going to actually need to make each of these into a BitmapData. I thought I would try the same trick, but BitmapData doesn't inherit the name property. So I'm back to using an array? Or is there another secret trick?

                            Thanks.
                            • 11. Re: How to Load Multiple PNGs in AS3
                              abeall Level 3
                              > I'm pretty sure that Loader doesn't inherit name from the Error class, and even if it
                              > does, that doesn't really help me learn how to use it, now does it! Formerly the
                              > answer to so many questions was, "Look it up in the help files." But now they
                              > really are almost useless.

                              Trying to use AS3 with the Flash CS3 IDE is pretty frustrating, to say the least.
                              • 12. Re: How to Load Multiple PNGs in AS3
                                Rothrock Level 5
                                To say the least!

                                If I didn't have a project that required immense buttloads of math I wouldn't even bother trying for AS3 at the moment. The speed difference is amazing – something that took 90 seconds in AS2 now takes about 10. So hopefully it will be worth it.
                                • 13. How to Load Multiple PNGs in AS3
                                  nelly_1 Level 1
                                  it inherits from DisplayObject.
                                  There is some problem with doing the same with Bitmaps -something to do with stuff already added in flash authoring cannot change name property but there are lots of other options
                                  function initHandler(event:Event):void {
                                  var image:Bitmap;
                                  image=Bitmap(event.target.content);

                                  var bitmap:BitmapData=image.bitmapData;
                                  addChildAt(image,count);
                                  trace(getChildAt(count));

                                  if (count < images.length-1) {
                                  count ++;
                                  startLoad(count);
                                  }
                                  }

                                  or maybe
                                  function initHandler(event:Event):void {
                                  var image:Bitmap;
                                  image=Bitmap(event.target.content);

                                  var bitmap:BitmapData=image.bitmapData;

                                  var s:Sprite = new Sprite()
                                  s.name ="s"+count
                                  s.addChild(image);
                                  addChild(s)

                                  if (count < images.length-1) {
                                  count ++;
                                  startLoad(count);
                                  }
                                  }


                                  EDI/T///////
                                  or maybe
                                  var s:Sprite = new Sprite()
                                  function initHandler(event:Event):void {
                                  var image:Bitmap;
                                  image=Bitmap(event.target.content);

                                  var bitmap:BitmapData=image.bitmapData;

                                  s.addChildAt(image,count);
                                  trace(s.getChildAt(count));
                                  addChild(s)
                                  if (count < images.length-1) {
                                  count ++;
                                  startLoad(count);
                                  }
                                  }