Solved

Load external animated gif at runtime

Posted on 2010-09-12
8
1,097 Views
Last Modified: 2013-11-11
Hi,

I've created a swf into which I am now trying to input an ad banner at the bottom.  The ad in particular is an animated gif and is being fetched from another domain.  I've tried putting it in an img tag but I only get the first frame.

Is there a way to reference an external animated gif and get it to display correctly without needing to import it to the library first?  I was hoping to be able to hold the information on the ads in a database table in order to be able to switch the ads more easily.

I am using Flash CS3 / Actionscript 3.

Thanks!

Emilie
0
Comment
Question by:Emilie
8 Comments
 
LVL 1

Expert Comment

by:ihaveitnow
ID: 33659004
Hi Emilie,

In actionscript 3 you are now able to use the Loader class. The Loader class can be used to load a JPEG, a GIF, a PNG, or an SWF file into another Flash movie during runtime.

All that is needed is to make an instance of the Loader class and call its load() method.

Hope this helps, regards.
var myLoader:Loader = new Loader();

myLoader.load(new URLRequest("link_to_external_file"));

addChild(myLoader);

Open in new window

0
 

Author Comment

by:Emilie
ID: 33659025
I run into the same problem with this solution.  The Loader can only contain one child at a time and hence cannot load the entire animation.  See Flash documentation : http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html

It clearly states that :
load(request:URLRequest, context:LoaderContext = null):void
Loads a SWF, JPEG, progressive JPEG, unanimated GIF, or PNG file into an object that is a child of this Loader object.

I just tried it anyways, and it in facts only load the first frame. :(
0
 

Author Comment

by:Emilie
ID: 33659162
Maybe someone can help me with this then.  To minimize the amount of code, I would like for every movieclip I import to library to use the same MouseEvent.Click function.  I am therefore trying to use the e.target.name property to decide to which url the event should redirect, but nothing happens when I click on the image.  What am I doing wrong?
adLeft1.addEventListener(MouseEvent.CLICK, goURL);
adRight1.addEventListener(MouseEvent.CLICK, goURL);
	
function goURL(e:MouseEvent):void {
   if (e.target.name == "adLeft1")
	navigateToURL(new URLRequest("http://www.madd.org/Under-21.aspx"));
   else if (e.target.name == "adRight1")
	navigateToURL(new URLRequest("http://www.missingkidsaver.com/"));
		
}			
	}

Open in new window

0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:Emilie
ID: 33659176
Never mind my latest question.  I had forgotten to set the name of my movieclips, aka adLeft1.name = "adLeft1".

But if anyone knows of a way to dynamically import an animated gif into a swf, I would still much prefer this solution than having to modifying the .fla everytime a new add gets added or removed from the rotation.
0
 
LVL 3

Accepted Solution

by:
cconstable_work earned 500 total points
ID: 33659227
Hi Emilie,

Check out http://www.bytearray.org/?p=95

They have created a class to do this in AS3.

0
 

Author Comment

by:Emilie
ID: 33661512
This class seems to be the most promising for anyone absolutely wanting to include an animated gif in their swf dynamically.  In the end, I simply made my swf shorter, created an iframe, and added the ads at the bottom through html and javascript.  It looks the same as if it were included in the swf, but is easier to manage.

Thanks to those who tried to help!
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 33672739
A lot of tools allow to convert an animated gif to an swf. If you have a relatively small set of image resources, this may be an option. In my case I wanted to create a chat with animated gif emoticons. I ended up converting them into SWFs that I could embed in my application. This made the memory footprint of my application a lot smaller than using a player component for each animated gif.
0
 

Author Closing Comment

by:Emilie
ID: 33846765
It is a good solution for certain types of gifs.  This class though, cannot be relied upon to render all types of animated gifs as some specific colors do not show up correctly once embedded.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question