Solved

Load external animated gif at runtime

Posted on 2010-09-12
8
1,089 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to record live broadcast.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now