Similar to a previous article How to load an image into our Flex application from URL(with source),the following source code shows three ways that how to load an image file.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="InitApp()">
<mx:Script>
<![CDATA[
//the first way:it will build "image.jpg" file into swf ( after building into swf,the image.jpg file is NOT needed)
[Bindable]
[Embed(source="image.jpg")]
private var imgClass:Class;
//the second way
private var _loader:Loader;
private function InitApp():void{
// source code of the first way
_img.source = imgClass;
//source code of the second way
_loader = new Loader();
//notice: NOT _loader.addEventListener,is _loader.contentLoaderInfo.addEventListener
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{
_img.source = e.currentTarget.content;
});
_loader.load(new URLRequest(encodeURI("image.jpg")));
//the third way
_img.source = "image.jpg"; //Notice: set img autoLoad's property to true
//image.jpg file is needed by the second and the third way's *.swf
}
]]>
</mx:Script>
<mx:Image x="51" y="62" width="298" height="245" autoLoad="true" id="_img"/>
</mx:Application>

March 9th, 2008
Ntt.cc
Posted in
Tags: 
RSS Feed
Email Feed
I am using Flex Builder 3 with Rails to develop a web based application. I want to load an Pdf file into browser, i tried out some techniques but it’s not working.
If you have any solution to this please let me know.
thanks
hi,Ajay
one component in flex 1.5 called flash paper which allows you
to render pdfs in flex ,but I don’t know whether is it available with Flex Builder 3.
[...] http://ntt.cc/2008/03/09/tips-three-ways-to-load-an-image-file-in-flex.html [...]
THANK YOU! This loader thing drove me crazy for more than an hour. thx for this post. even if its old.
Carsten
Hi i want to assign an image to a bit mapdata.
How i do that?
[...] introduced three ways to load an image file in Flex in previous article. Normally there are no any problem with loading progress of external files. You [...]