Skip to main content
Participating Frequently
March 10, 2011
Question

Loading an external image (from file system) to fla library as MovieClip symbol using ActionScript.

  • March 10, 2011
  • 1 reply
  • 754 views

Hi everyone,

I am new to actionscript and Flash.

I have been working on code updation project wherein initially we had an image and text as movieclips in fla library. The image and the text are read by the actionscript program which then creates an animation.

For Example:

// Picture

// *******************************************************

// _imageMC: Name of the Movie Clip in the libary which

// contains the picture.

var _imageMC:String = "polaroid";

This is later on used by another actionscript class as follows to finally create the animation.

var _mcPolaroid:MovieClip = this._mcBg.attachMovie(this._polaroid, "polaroid_mc", this._mcBg.getNextHighestDepth());

Now the problem here is when one needs to update the image or text, one needs to go and open the fla file andmanually change the image attached to the movieClip (polaroid).

I want to ease the updation process by giving the url of the image in an XML file. Read the image url from the xml and load this image in the library of the fla as movieclip. This, i think, will result in less code change and improve the updation of the final animation image.

The problem i am facing is not been able to figure out how can i change the image (after fetching its URL) to a movieclip and then load it in the library?

Thank you kindly in advance,

Varun

This topic has been closed for replies.

1 reply

varunsudAuthor
Participating Frequently
March 10, 2011

just to explain a bit more clearly,

since the following code takes a string whose value is the name of the movieclip in the library, i want to automatically load the image (from xml) using actionscript and convert it to a movieclip symbol named 'polaroid'. This way i am just changing the xml file everytime i need to change the image in the animation. I am not touching FLA file to load the image as movieclip symbol in the library manually.

// Picture

// *******************************************************

// _imageMC: Name of the Movie Clip in the libary which

// contains the picture.

var _imageMC:String = "polaroid";

Ned Murphy
Legend
March 10, 2011

If you look up the loadMovie() function in the Flash help documentation it should have examples of how you can dynamically load an external file into a dynamically created movieclip using the createEmptyMovieClip() function.  You should read thru the entire section so that you gain a good understanding of how the tool you want to use works.

In your case, instead of using the attachMovie code you could use something like...

this.createEmptyMovieClip("polaroid", this.getNextHighestDepth());
loadMovie("imagefile.jpg", polaroid);

where you would end up substituting your xml variable for the "imagefile.jpg" url (no quotes for a variable)

You should also be aware of the MovieClipLoader class and its loadClip() method, which is another means of loading external files dynamically.  The difference is that the MovieClipLoader class supports having listeners in the event you need to know where you are in the loading process and/or when it completes.

varunsudAuthor
Participating Frequently
March 11, 2011

Great! i will do that. Thanks a lot!  God bless you!