Sad Code Monkey

Sad, yes, but also brilliant.

 

Sad Code Monkey is a place where we document new-found techniques and code snippets, and share our knowledge with other code monkeys.

Let’s keep this one simple. There are different ways to code loading a SWF into the main movie depending on where you are. Here are the two scenarios:

If you’re coding on the timeline, main movie.

Say we want to load another SWF and we want to scale it to 50%. Decide at what keyframe in the main movie timeline you want the SWF to load and add the following code:

loadMovie(“my_movie.swf”, “_level5″);
_level5._x=0;
_level5._y=0;
_level5._xscale=50;
_level5._xscale=50;

The level can be any number you want. It just can’t be level 0 – that’s the main timeline. The four lines of code below the loadMovie command place the SWF at the top left corner of the main movie (0,0) and make it 50% size. If and when you want to remove the SWF, you simply place the following code in another keyframe on the main timeline:

unloadMovie(“_level5″);

If you’re coding a button.

If you’re coding a button, simply put the following code into your ActionScript panel:

on (release) {
loadMovie(“my_movie.swf”, “_level5″);
}

For a button to remove the SWF, add this code:

on (release) {
unloadMovie(“_level5″);
}

Notice here that you only need to declare the level of the movie. The code will remove any movie that is occupying level 5. I hope I kept it simple enough for others out there like me who just want to add and remove SWF files.

Comments are closed.