Solved

Load external animated gif at runtime

Posted on 2010-09-12
8
1,114 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
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.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

742 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