Solved

Load external animated gif at runtime

Posted on 2010-09-12
8
1,081 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Accepted Solution

by:
cconstable_work earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
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…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

744 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

18 Experts available now in Live!

Get 1:1 Help Now