6 Replies Latest reply on Oct 15, 2010 5:32 AM by Scotlad86

    Image Loader

    Scotlad86

      I have a barCode class that is used to generate an image of a barCode. I create an instance of this class and it works as expected for example:

       

      var myBarCodeInstance:barCode = new barCode();

       

      var myBarCodeImg:Image = new Image();

      myBarCodeImg.source = myBarCodeInstance;

       

       

      Using this code the image appears and works fine. However, my question is how do I implement a loader on this image that will fire an event when the image is fully loaded and ready for processing? (I am running into null problems with the image not being fully loaded before attempting to access its contents).

       

       

      Something like the below:

       

       

       

      var loader:Loader;

       

      loader = new Loader();

      loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{

      myBarCodeImg.source = e.currentTarget.content;

      // further processing here

      });

      loader.load(new URLRequest(encodeURI(“image.jpg“)));

       

       

      but i dont know what to insert in place of the "image.jpg" part due to my image being an instance of a class and not an actual jpg file.

       

      Any help appreciated!

        • 1. Re: Image Loader
          Flex harUI Adobe Employee

          Content should be ready in the COMPLETE event.

          • 2. Re: Image Loader
            Scotlad86 Level 1

            Hi, thanks for help I am still having an issue with this, can you tell me why the below code does not work for me? The logo image displays as expected but the event.complete does not seem to fire as the trace('IMAGE LOADED'); does not appear

             

             

            <?xml version="1.0" encoding="utf-8"?>

            <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

               xmlns:s="library://ns.adobe.com/flex/spark"

               xmlns:mx="library://ns.adobe.com/flex/mx">

            <fx:Declarations>

            <!-- Place non-visual elements (e.g., services, value objects) here -->

            </fx:Declarations>

             

             

            <fx:Script>

            <![CDATA[

             

            import mx.controls.Image;

            import mx.events.FlexEvent;

            [Embed(source="../images/logo.jpg")]

            [Bindable]

            public var logoImg:Class;

             

             

            var tempImg:Image;

             

            protected function testBut_clickHandler(event:MouseEvent):void

            {

             

            trace('button pressed')

            tempImg = new Image();

            tempImg.addEventListener(Event.COMPLETE, function(e:Event):void{ trace('IMAGE LOADED'); } )

            tempImg.source = logoImg;

            addElement(tempImg);

             

             

            }

             

            ]]>

            </fx:Script>

             

            <s:Button x="86" y="14" label="test" id="testBut" click="testBut_clickHandler(event)"/>

             

            </s:WindowedApplication>

            • 3. Re: Image Loader
              Claudiu Ursica-USyc3k Level 1

              I think the loader should dispatch the complete event, you should listen on the

              loader not the image.

               

              C

              • 4. Re: Image Loader
                Scotlad86 Level 1

                Hi, as my first post explained I dont know how to load the barCodeInstance into the loader, Do you have an example? btw this is an AIR app if that makes any difference.

                 

                loader.load(new URLRequest(encodeURI(“image.jpg“))); <---  how to load the barCodeInstance rather than the URL  'image.jpg'  since my image does not have a URL due to being an instance of a class ?

                • 5. Re: Image Loader
                  l33tian Level 1

                  Hi...This is not a reply to your question and i'm sorry if you are dissapointed but your barcode class caught my eye...i'm trying to implement a barcoding functionality in a Content Management System i'm building with Adobe AIR/Flex. And i am just curious on how your class works...I will really appreciate it if we meet on yahoo. denachural@yahoo.com is my yahooid. My facebook name is Larry Eliemenye. Would really love to discuss cos it seems we are doing something similar...thanks

                  • 6. Re: Image Loader
                    Scotlad86 Level 1

                    Hey there I did not create the component you can check it out here..

                     

                    http://www.adobe.com/devnet-archive/flex/tourdeflex/web/#docIndex=0;illustIndex=0

                     

                    developer http://nathanpdaniel.com