4 Replies Latest reply on Dec 12, 2010 7:42 AM by senbon1001

    Loading and displaying an image using a Flex 4 project

    senbon1001

      Hi all:

       

      I am trying to load and display an image and unfortunately the image does not display. When I run my Flash application in a debug Flash player I got an error message saying that I need to use addElemement instead of addChild in my .mxml file and after I made the changes the image still does not appear I have pasted the code that wrote. Therefore would someone be kind enough to tell me what I am doing wrong? Am I missing something? Thanks in advance,

       

      The .mxml file:

       

       

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

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

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

         xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768"

         creationComplete="initApp();">

      <fx:Declarations>

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

      </fx:Declarations>

       

      <fx:Script>

      <![CDATA[

      public function initApp():void

      {

      var arrayManipulator:ArrayManipulation = new ArrayManipulation();

      addElement(arrayManipulator);

      arrayManipulator.main();

      }

       

      ]]>

      </fx:Script>

       

      </s:Application>

       

       

      The .as file:

       

      package

      {

      import flash.display.Loader;

      import flash.display.Sprite;

      import flash.events.Event;

      import flash.events.ProgressEvent;

      import flash.net.URLRequest;

      import spark.core.SpriteVisualElement;

       

      public class ArrayManipulation extends SpriteVisualElement

      {

       

      public var imgLoader:Loader;

       

       

      public function ArrayManipulation()

      {

      }

       

       

      public function onProgress(e:ProgressEvent):void

      {

      }

       

       

      public function onCompletion(e:Event):void

      {

      addChild(imgLoader);

       

      }

       

       

       

      public function main():void

      {

      imgLoader = new Loader();

      imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

      imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompletion);

       

       

       

      imgLoader.x = 125;

      imgLoader.y = 38;

      imgLoader.width = 420;

      imgLoader.height = 251;

       

      imgLoader.load(new URLRequest("luminance_blend3.jpg"));

      }

      }

      }