Loading External Sources - Images and SWF

Category : Flash Views : 12379
Version : 8 Rating
2.7/5 (25 votes)
Type : Text Source File: loading-external-sources-images-swf.zip
Result: See the result


This method is very useful; sometimes you want to be able to easily change how your movie works, but you don’t want to have to change you code.
For example, I created a movie clip that is an image. But a few days later I changed my mind and a want another image. I don’t even need the source code; I just delete the old image and rename the new one.
And that works for .swf files too, delete the old and rename the new one.

Let’s see how this works.

Create two buttons, name one "imgBtn" and the other "swfBtn".
imgBtn will load an image and swfBtn will load a movie.

Before we continue, you need to save the project and have two files on the same folder:
"pic.jpg" – the picture
"movie.swf" – the movie
Pick any picture and movie that you have, it works great with anything you want.

Now open the actions for the first frame. Paste this:
imgBtn.onRelease = function() { _root.createEmptyMovieClip("holder", 1) loadMovie("pic.jpg", "holder"); _root.holder._xscale = 50; //width scale _root.holder._yscale = 50; //height scale }

When we click the button we create a new Movie Clip:
_root.createEmptyMovieClip("holder", 1)
It will hold our image and help us to scale it later.

Then we call the loadMovie() function:
loadMovie("pic.jpg", "holder");
The first parameter is the path to the picture we are going to load, as it is in the same folder of our project we don’t need to include the entire path.

Finally we scale the picture to 50%, because it was too big.
_root.holder._xscale = 50; _root.holder._yscale = 50;

Done! Try changing the picture outside the code to see that it will work too.
Free Flash Tutorials, Loading External Data, External Sources, Loading Images and SWF

With .swf files is the same thing:
swfBtn.onRelease = function() { _root.createEmptyMovieClip("holder", 1) loadMovie("movie.swf", "holder"); _root.holder._xscale = 80; //width scale _root.holder._yscale = 80; //height scale }
I changed the button event from "imgBtn" to "swfBtn" and the scaled to 80% instead of 50%.

Test it now. I used an animated movie I did previously and it worked perfectly.
Free Flash Tutorials, Loading External Data, External Sources, Loading Images and SWF

If you want to make a customizable movie, loading is much better than hard coding everything.

del.icio.us digg it Reddit Stumble Upon Technorati




Supporters

Reseller Web Hosting