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.

2 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

Add a New Comment


code
 

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