Forum Topic: AS3: Loading external images

(11,588 views • 4 replies)

This topic is 1 page long.

<< < > >>
Thinking

LilFugitive

Reply To Post Reply & Quote

Posted at: 12/15/07 07:32 AM

LilFugitive EVIL LEVEL 16

Sign-Up: 06/01/06

Posts: 568

What am I going to explain?

I'm going to explain how to load an external image from a URL and place it in your flash. If you have an image URL that will change every day, then the image in your flash will change every day. Don't worry this isn't complicated at all ;)
----------------------------------------
----------------------------------------
----------------------------------------
--------------------

Now let's start with the code!

For this code we need:
a Loader
and a URLRequest

We'll first start with making a loader:

var imageLoader:Loader = new Loader();

Note that imageLoader can have any name but you'll have to change it also in the rest of the code.

Afterwards we'll add an URL request by typing this in the actions window:

var image:URLRequest = new URLRequest ("http://img.ngfiles.com/emoticons/emote-1.gif");

Note that image and the URL can be customizable, but if you change the name of the URL request you'll have to change it in the rest of the code. Also the URL must have only an image, so not a site with a image, but only the image.

Now we want the loader to load the request, so we type this:

imageLoader.load(image);

And as last we add the loader with the request:

addChild (imageLoader);

When we the image is on the stage it'll have as default it's x and y values 0.
If you want to change it, you can do it like this:

imageLoader.x = 200;
imageLoader.y = 300;

Note you can choose what the x and y values are
----------------------------------------
----------------------------------------
----------------------------------------
--------------------
This is the complete code

var imageLoader:Loader = new Loader();
var image:URLRequest = new URLRequest("http://img.ngfiles.com/emoticons/emote-1.gif");
imageLoader.load(image);
addChild (imageLoader);
imageLoader.x = 200;
imageLoader.y = 300;

----------------------------------------
----------------------------------------
----------------------------------------
--------------------
If you discover a mistake or you're having problems, PM me or leave a comment here.

Ruining your life since 2006

BBS Signature

None

LilFugitive

Reply To Post Reply & Quote

Posted at: 12/16/07 03:48 AM

LilFugitive EVIL LEVEL 16

Sign-Up: 06/01/06

Posts: 568

Wow! I explained it well if no one responds :)
(and then there come millions of angry responses xD)

Ruining your life since 2006

BBS Signature

None

archont

Reply To Post Reply & Quote

Posted at: 12/16/07 08:15 AM

archont NEUTRAL LEVEL 01

Sign-Up: 09/24/06

Posts: 377

Note: Loader works well for one image but when you need multiple images take a look at bulkloader:

Bulkloader

It's some pretty nice programming as well, extending the flash event handling class.


Elated

benparsons

Reply To Post Reply & Quote

Posted at: 3/16/09 07:34 AM

benparsons NEUTRAL LEVEL 01

Sign-Up: 03/16/09

Posts: 1

At 12/16/07 03:48 AM, LilFugitive wrote: Wow! I explained it well if no one responds :)
(and then there come millions of angry responses xD)

Ah, not to worry, I liked it. Thanks for explaining.


None

LostDZ

Reply To Post Reply & Quote

Posted at: 3/16/09 05:16 PM

LostDZ NEUTRAL LEVEL 11

Sign-Up: 12/09/07

Posts: 1

Thanks for this mini-tutorial!


All times are Eastern Standard Time (GMT -5) | Current Time: 11:23 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!