Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Load external animated gif at runtime

Posted on 2010-09-12
8
Medium Priority
?
1,152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
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…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

636 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