Using the Loader class in AS3

Using the Loader class in AS3

I recently worked on a project that required the user to upload a photo of themselves via a web form, and this photo would then be used in a Flash animation.

This required using the Loader class that loads external assets (such as images and Flash files) at run time into a Flash movie. For more information about using the AS3 Loader class, take a look at the fantastic tutorial at Republic of Code. Below is a shortened example of how the image was loaded.

The first line of our code simply created an instance of the Loader Class, the instance name is my_loader.

The second line loaded the external image using the .load() method. This method requires the URL to be provided to it through the URLRequest Class. The URLRequest can be instantiated through different methods, the one shown in our code below is the shortest and easiest one to use.

var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("photo.jpg"));

This instance of the Loader class was then used in two different MovieClips at different times during the Flash animation. For simplicity, I'll refer to these MovieClips as MovieClip A and MovieClip B.

The first frame of MovieClip A and B, adds the instance of the Loader class to the respective MovieClip so that we can see the image on the screen.

mc_photo.addChild(my_loader);
addChild(my_loader);

MovieClip A displayed the instance of the Loader class without any issues. For a reason I am not 100% certain about, the Loader class instance in MovieClip B would either flicker or not display at all.

I tried using the CacheAsBitmap property, but as I was altering the position of the Loader instance in a multi-fram animation, this actually had an adverse effect on the performance of the movie.

After many hours of trying to find a solution, I decided upon having 2 Loader instances with the same image.

var my_loader_1:Loader = new Loader();
my_loader_1.load(new URLRequest("photo.jpg"));
var my_loader_2:Loader = new Loader();
my_loader_2.load(new URLRequest("photo.jpg"));

If anyone has any ideas about why this was happening, please feel free to add a comment below.

21 comments (Add your own)

1. udunusocew wrote:
http://mewkid.net/buy-amoxicillin/ - Amoxicillin No Prescription Amoxicillin Online ocn.iwlf.smdool.co.uk.hvk.cp http://mewkid.net/buy-amoxicillin/

Fri, June 28, 2019 @ 10:01 PM

2. tobahug wrote:
Pancreatitis, gpp.obzi.smdool.co.uk.trw.ne hypercalcaemia; concentrate lowering, [URL=http://quotes786.com/eriacta-for-sale/ - price eriacta[/URL - [URL=http://cocasinclair.com/online-viagra/ - viagra[/URL - [URL=http://appseem.com/cheap-viagra/ - viagra[/URL - [URL=http://solartechnicians.net/ventolin-inhaler/ - ventolin inhaler for sale[/URL - [URL=http://alwaseetgulf.com/viagra-100mg/ - viagraonline.com[/URL - jeopardise gravidarum paralyze eriacta for sale buy viagra viagra ventolin hfa 90 mcg inhaler copay assistance viagra on internet campaigns painless, http://quotes786.com/eriacta-for-sale/#generic-eriacta para que sirve el fefol eriacta online eriacta http://cocasinclair.com/online-viagra/#viagra-generic viagra http://appseem.com/cheap-viagra/#viagra viagra http://solartechnicians.net/ventolin-inhaler/#ventolin-inhaler price of ventolin inhaler http://alwaseetgulf.com/viagra-100mg/#viagra price of 100mg viagra woman, synthesized.

Fri, June 28, 2019 @ 10:14 PM

3. wrote:
hard celebration [url=http://www.vagragenericaar.org/]viagra prices[/url] since run
honest supermarket viagra without a doctor prescription uk
virtually extent

Tue, September 3, 2019 @ 9:05 AM

4. wrote:
greatly access [url=http://www.viagrapid.com/]where to buy viagra online[/url] when bath
totally midnight best price 100mg generic viagra late rock

Tue, September 3, 2019 @ 1:54 PM

5. wrote:
ill advance [url=http://www.viagenupi.com/]generic viagra sales[/url]
absolutely perspective
naturally tennis generic viagra sales flat language

Wed, September 4, 2019 @ 6:00 AM

6. wrote:
perfectly breast [url=http://www.cialij.com/]ed
pills in puerto rico[/url] any closet
especially attack generic ed pills online from canada forth reception

Thu, September 5, 2019 @ 12:30 AM

7. wrote:
sildenafil ad good morning [url=http://viacheapusa.com/]viagra india 100mg price[/url] sildenafil and diovan hct

Thu, September 5, 2019 @ 4:01 AM

8. wrote:
close garage [url=http://www.cialisps.com/]buy cialis on the internet[/url] small sir
suddenly establishment buy cialis on the internet previously control

Fri, September 6, 2019 @ 12:07 AM

9. wrote:
h http://cialisles.com/ cialis 20 mg best price, such donde comprar cialis online cialis and cialis.com

Fri, September 6, 2019 @ 5:19 AM

10. wrote:
truly leg [url=http://www.viatribuy.com/]viagra[/url] when object
probably mud generic viagra online pharmacy aside budget

Fri, September 6, 2019 @ 9:11 AM

11. wrote:
canada tadalafil 5mg [url=http://cialislet.com/]cialis prices[/url]
cialis 5 mg no brasil.

Sat, September 7, 2019 @ 8:24 PM

12. wrote:
running expect http://cialisle.com/ that
stone http://cialisle.com absence
university [url=http://www.cialisle.com/]cialis pills[/url] comfortable

Sun, September 8, 2019 @ 4:02 PM

13. wrote:
totally plant [url=http://oakley-sunglassesformen.us/]generic viagra online pharmacy[/url] forth equipment
through magazine viagra online rather somewhere

Mon, September 9, 2019 @ 9:44 AM

14. wrote:
likely elevator mainly stranger http://www.doctor7online.com/ tomorrow flower
completely anger viagra cheapest eventually creative
forth permit [url=http://www.doctor7online.com/]cheap generic viagra online[/url] less remove

Mon, September 9, 2019 @ 8:42 PM

15. wrote:
wide youth slowly maintenance http://genericalis.com/ today depth
never guest generic cialis at walmart therefore
risk
yesterday problem [url=http://genericalis.com]cialis online[/url] any video

Tue, September 10, 2019 @ 8:11 AM

16. wrote:
next gold gently examination http://cialissom.com/ constantly insect
actually convert order cheap cialis originally
concern
down criticism [url=http://cialissom.com]cheap cialis over the counter[/url] greatly
care

Wed, September 11, 2019 @ 3:55 PM

17. wrote:
screen sugar http://viabsbuy.com/ experience
data viagra online exchange
possibility [url=http://viabsbuy.com]viagra online[/url]
plate

Thu, September 12, 2019 @ 6:37 AM

18. wrote:
yesterday cream [url=http://christianlouboutinoutletus.us/]how much is generic viagra at walmart[/url] seriously
animal
instead piano viagra generic at walgreens virtually register

Fri, September 13, 2019 @ 6:15 PM

19. wrote:
definitely poet [url=http://cavalrymenforromney.com/]cenforce 200 for sale[/url] tight park small error http://cavalrymenforromney.com/ originally diamond occasionally match cenforce 120mg any shoot

Thu, September 19, 2019 @ 9:16 AM

20. wrote:
sildenafil medana allegro
generic viagra
sildenafil masticable como se toma
[url=http://viarowbuy.com/]viagra online prescription[/url]

Fri, October 4, 2019 @ 11:44 PM

21. wrote:
strong kratom http://kratomsaleusa.com kratom strains guide

Sun, October 6, 2019 @ 11:21 AM

Add a New Comment


code
 

Comment Guidelines: No HTML is allowed. Off-topic or inappropriate comments will be edited or deleted. Thanks.