The following example shows how you can dynamically load an external image into a Flash/ActionScript 3.0 UILoader container by setting the source property to a URL or calling the load() method and passing a URLRequest object.
Full code after the jump.
The following example auto loads an external image by setting the source property to an image URL:
// ActionScript 3.0 /* Requires: * - UILoader control in Library */ import fl.containers.UILoader; var uiLoader:UILoader = new UILoader(); uiLoader.source = "http://helpexamples.com/flash/images/image1.jpg"; uiLoader.move(10, 10); addChild(uiLoader);
The following example loads an external image using the load() method and a URLRequest object:
// ActionScript 3.0 /* Requires: * - UILoader control in Library */ import fl.containers.UILoader; var urlReq:URLRequest = new URLRequest(); urlReq.url = "http://helpexamples.com/flash/images/image1.jpg"; var uiLoader:UILoader = new UILoader(); uiLoader.load(urlReq); uiLoader.move(10, 10); addChild(uiLoader);
{ 9 comments… read them below or add one }
I think use Loader to load a image must be better,because Loader is more light than UILoader.
Loader is extends Loader DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object
And UILoader is extends UILoader UIComponent Sprite DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object
When we load thousands of images,loader will user less memory.:)
hello,
i need to create 3 buttons. when clicked on any of them they take me to a jpg or sfw file using the uiloader technique. can someone tell me how to do this
thank u
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var myTween1:Tween = new Tween(pic1_btn, “x”, Bounce.easeOut, -100, 1000, 2, true);
var myTween2:Tween = new Tween(pic2_btn, “x”, Bounce.easeOut, -100, 850, 2, true);
var myTween3:Tween = new Tween(pic3_btn, “x”, Bounce.easeOut, -100,700, 2, true);
var myTween4:Tween = new Tween(pic4_btn, “x”, Bounce.easeOut, 100, 400, 2, true);
var myTween5:Tween = new Tween(pic5_btn, “x”, Bounce.easeOut, 100, 250, 2, true);
var myTween6:Tween = new Tween(pic6_btn, “x”, Bounce.easeOut, 1000, 100, 2, true);
var myTween7:Tween = new Tween(pic7_btn, “x”, Bounce.easeOut, 1050, 550, 2, true);
//This tells the movie clips to act like buttons
pic1_btn.buttonMode = true;
pic2_btn.buttonMode = true;
pic3_btn.buttonMode = true;
pic4_btn.buttonMode = true;
pic5_btn.buttonMode = true;
pic6_btn.buttonMode = true;
pic7_btn.buttonMode = true;
function Pic1(e:MouseEvent):void
{
display.source = “pic1.swf”;
}
function Pic2(e:MouseEvent):void
{
display.source = “pic2.swf”;
}
function Pic3(e:MouseEvent):void
{
display.source = “pic3.swf”;
}
function Pic4(e:MouseEvent):void
{
display.source = “pic4.swf”;
}
function Pic5(e:MouseEvent):void
{
display.source = “pic5.swf”;
}
function Pic6(e:MouseEvent):void
{
display.source = “pic6.swf”;
}
function Pic7(e:MouseEvent):void
{
display.source = “pic7.swf”;
}
pic1_btn.addEventListener(MouseEvent.CLICK, Pic1);
pic2_btn.addEventListener(MouseEvent.CLICK, Pic2);
pic3_btn.addEventListener(MouseEvent.CLICK, Pic3);
pic4_btn.addEventListener(MouseEvent.CLICK, Pic4);
pic5_btn.addEventListener(MouseEvent.CLICK, Pic5);
pic6_btn.addEventListener(MouseEvent.CLICK, Pic6);
pic7_btn.addEventListener(MouseEvent.CLICK, Pic7);
If I use the code to load my own images, they are loaded and resized to a very small picture. How can I change the size of this picture?
try this code timo
uiLoader.setSize(150,200);
or u can add this:
loader.scaleContent = false;
it will risize the loader to the size of every image
How can you load something that is already in the library?
you can add a linkage name in the library such as MyObject and then just set uiLoader.source = MyObject .
How to unload the UILoader