12 Replies Latest reply: Jun 18, 2012 3:38 AM by screeen RSS

    how do i load a sequence of numbered images using AS3.0?

    screeen Community Member

      To avoid importing loads of images into a Flash file and putting them on the timeline, i should like to simulate a movie clip by using an image-sequence, that is, by sequentially loading a series of still images, to& then, to "activate" - or view the sequence upon mouse-click, .

       

      i figure this involves a loop and array, but i can't figure out the code.

      Plz help.

      thanks.

        • 1. Re: how do i load a sequence of numbered images using AS3.0?
          Ned Murphy MVP

          To sequentially load anything you need to use a functional loop (and the array and a counter variable).  The basics of it are outlined below, but not in actual coding syntax, mainly descriptive...

           

          var array:Array = new Array(your array of images); (if these are numerically named, then you may not need the array, just a count value so you know when to stop)

           

          var count:int = 0;

           

          function loadCurrentI mage(){

               loader.load(array[count])

               loader.contentLoaderInfo.addEventListener(COMPLETE,loadComplete)

          }

           

          function loadComplete(evt...){

           

               // first process loaded image, then...

           

              count++;

              if(count < array.length){

                  loadCurrent();  // load the next image

              } else {

                  // sequencial loading complete, carry on to next activity

              }

                 

          }

          • 2. Re: how do i load a sequence of numbered images using AS3.0?
            screeen Community Member

            hi Ned. Have built it up to proper syntax but getting an error:

            Scene 1, Layer 'Layer 1', Frame 1, Line 51067: Implicit coercion of a value of type Array to an unrelated type String.

             

             

            This happens when the jpg images are in the same directory as the FLA file.

             

             

            On the other hand, when the images are in a folder on their own, also in the same file as the FLA file, using the path in AS URL request (var req:URLRequest = new URLRequest("../twirl_test"+imageArray); i get a security error that i've experienced in the past as relating to improper path: SecurityError: Error #2000: No active security context.

            • 3. Re: how do i load a sequence of numbered images using AS3.0?
              Ned Murphy MVP

              I can't help with the 1067 error without seeing the code.

              • 4. Re: how do i load a sequence of numbered images using AS3.0?
                screeen Community Member

                import flash.net.URLRequest;

                import flash.display.Loader;

                import flash.events.Event;

                 

                var count:int = 0;

                 

                var imageArray:Array=["image1.jpg","image2.jpg","image3.jpg","image4.jpg","image5.jpg","image 6.jpg","image7.jpg",

                "image8.jpg","image9.jpg","image10.jpg"];

                 

                var url:String = "D:/flash cs5.5/image_sequence/twirl_test/"+imageArray;//TypeError: Error #2007: Parameter url must be non-null.

                //var req:URLRequest = new URLRequest("../twirl_test/"+imageArray);

                var request:URLRequest = new URLRequest(url);//SecurityError: Error #2000: No active security context.

                var loader:Loader = new Loader();

                 

                //this is if u dont want the loader on the stage BETTER PRACTICE

                function imageLoaded(event:Event):void

                {

                    addChild(loader);

                }

                 

                loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);

                loader.load(request);

                 

                 

                 

                 

                 

                 

                function loadCurrentImage(){

                 

                     loader.load(imageArray[count])

                 

                     loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete)

                }

                 

                function loadComplete(event:Event){

                 

                     // first process loaded image, then...

                 

                    count++;

                 

                    if(count < imageArray.length){

                 

                        loadCurrentImage();  // load the next image

                 

                    } else {

                 

                        // sequencial loading complete, carry on to next activity

                 

                    }

                }

                • 5. Re: how do i load a sequence of numbered images using AS3.0?
                  Ned Murphy MVP

                  var url:String = "D:/flash cs5.5/image_sequence/twirl_test/"+imageArray;

                   

                  That array being added to the end isn't going to do much for you.  I am guess you really just wanted one element of the array, not the array itself.

                  • 6. Re: how do i load a sequence of numbered images using AS3.0?
                    screeen Community Member

                    one element added at a time.

                     

                    any help, from anyone, would be appreciated.

                     

                    Ned, i am wondering if this - adding images sequentially to have a moving-image effect may be done using indexing - by adding one image to one loader on one frame? if so, can u help with the code for index? i cant remember how it's done. thanks for your help.

                    • 7. Re: how do i load a sequence of numbered images using AS3.0?
                      Ned Murphy MVP

                      If you only want one element, then only specify one element.  Using "imageArray" like you show is attempting to assign an array to a string.  One element involves specifying an index value... imageArray[index]

                      • 8. Re: how do i load a sequence of numbered images using AS3.0?
                        screeen Community Member

                        Ned, sorry, this is too cryptic for me to follow, i suppose i need to see examples of code to know what u mean.

                        thanks anyway.

                        best.

                        • 9. Re: how do i load a sequence of numbered images using AS3.0?
                          Ned Murphy MVP

                          YOu've already provided the example, you just need to realize what you have written versus what you want to write.

                           

                          var url:String = "D:/flash cs5.5/image_sequence/twirl_test/"+imageArray;

                           

                          What do you imagine that "imageArray" is doing at the end of your line of code there?

                          • 10. Re: how do i load a sequence of numbered images using AS3.0?
                            screeen Community Member

                            i imagine that once the path is established (the string), imageArray is the variable specified for it. The array - imageArray, is, i am imagining, the still images inside the folder thats in the url string, and therefor, in adding imageArray, it's like referring to the group of images versus one specific image, as such "D:/flash cs5.5/image_sequence/twirl_test/image1.jpg

                             

                            so instead of getting image1.jpg, i am trying to tell Flash to get the images in the array, in accordance with their numeric order.

                             

                             

                            that's what i imagine.

                            • 11. Re: how do i load a sequence of numbered images using AS3.0?
                              Ned Murphy MVP

                              If that is what you think you want to do, then that is the problem.  You only want to ask for one image at a time.  By appending the entire array to the url, your attempting to add apples (an array) to oranges (a string)... they are two different classes of objects.  You want to add strings to strings... and your array contains individual strings.

                              • 12. Re: how do i load a sequence of numbered images using AS3.0?
                                screeen Community Member

                                Ned. i simply do not know how to load a sequential array of images, so if you know how to and would like to share the code. Please do.

                                thanks.