4 Replies Latest reply on Mar 8, 2010 5:27 AM by FaBritze

    Uploading images...

    FaBritze Level 1

      I created a class that loads the images according to an xml file that indicates where the images are and this class extends the dispatch event that allows my main class, with an instantiated object, access to these images. But to add to the stage I can not add in the order along with the text that I created in the main class. I would like an aid, if it has to understand my problem ...

        • 1. Re: Uploading images...
          Ned Murphy Adobe Community Professional & MVP

          If you want ordered control of loading images, you need to load them sequentially.  To load sequentially you need to load one file at a time, and have a load completiong function trigger loading the next file.  The primary tools for this include... an array listing the images to load, a counter to target an image in the array for loading, function that loads an image and assigns a listener for load completion, as load completion function that processes the loaded image--increments the counter, and calls the loading function to load again if there are more files left to load.

          • 2. Re: Uploading images...
            FaBritze Level 1

            I think i already doing that, I will show my code to you understand better:

             

            package com.fabricio.dados{

             

            import flash.display.*;

            import flash.events.*;

            import flash.net.*;

             

            public class ImageLoader extends EventDispatcher {

             

            private var capa:Array;

            private var descricao:Array;

             

            private var total:Number = 0;

             

            private var loader:Loader;

             

            XML.ignoreWhitespace = true;

            //--

            public function ImageLoader(IDFotografo:Number) {

            capa = new Array();

            descricao = new Array();

             

            var xmlLoader:XmlLoader = new XmlLoader("http://www.dominio.com/MyXml" + IDFotografo + "&Ordenacao=0");

            xmlLoader.addEventListener(Event.COMPLETE,onComplete);

            xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,ioError);

            }

            //--

            private function onComplete(evt:Event):void {

            evt.currentTarget.removeEventListener("COMPLETE",onComplete);

            //--

            carregarImagem(total);

            //--

            function carregarImagem(i:Number):void {

            if (evt.currentTarget.getXml.. @ existePasta[i] == 1) {

            var urlRequest:URLRequest = new URLRequest("hhttp://www.dominio.com/web/layout/" + evt.currentTarget.getXml. @ pastaFotografo + "/galeria/" + evt.currentTarget.getXml.. @ pasta[i] + "/01.jpg");

            //trace(urlRequest.url);

            descricao.push(evt.currentTarget.getXml..@descricao[total]);

            loader = new Loader();

            loader.load(urlRequest);

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

            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorLoader);

            } else {

            trace(urlRequest.url);

            trace("A pasta " + evt.currentTarget.getXml..@pasta[i] + " não existe...");

            }

            total++;

            if (total < evt.currentTarget.getXml.children().length()) {

             

            carregarImagem(total);

            }

            }

            //--

            }

            //--

            private function ioError(err:IOErrorEvent):void {

            err.currentTarget.removeEventListener("IO_ERROR",ioError);

             

            trace("Ocorreu o seguinte erro ao instanciar o XmlLoader: " + err.text);

            }

            //--

            private function onCompleteLoader(evt:Event):void {

            evt.currentTarget.removeEventListener("COMPLETE",onCompleteLoader);

            capa.push(evt.currentTarget.content);

             

            dispatchEvent(new Event(Event.COMPLETE));

            }

            //--

            private function ioErrorLoader(err:IOErrorEvent):void {

            trace("Ocorreu um erro ao carregar a imagem: " + err.text + "\n");

            }

            //--

            public function get getDescricao():Array {

            return descricao;

            }

            //--

            public function get getCapa():Array {

            return capa;

            }

            //--

            }

            }

             

            Using this way the images are loaded correctly but at random, so the texts, which are in the correct order, are in the wrong order ...

            • 3. Re: Uploading images...
              FaBritze Level 1

              My problem is the legend that I am trying to put the image, the images are being displayed as downloaded, that is, if one takes a little longer than the other to be displayed before it is displayed, so the captions do not have this delay stay with the fixed position while the images, probability, almost never get the same position.How can I make the loading of the image and caption them and display them together?

              • 4. Re: Uploading images...
                FaBritze Level 1

                Tanks a lot for your help, i find the answer