A few days ago when I was surfing the internet I stumbled upon an especially pesky ad. Not only did it clog up the whole screen but also it ran away everytime my mouse approached its cancel-button! Of course, after a while I succeeded in getting rid of the unwelcome intruder. Well, it seems as though "every cloud has a silver lining" because, thanks to this ad, I can now be writing this tutorial. :-)
Upon completing this tutorial, you will be able to create such a running ad.
Let's start
i. Traditionally, create a new Flash document. Set the width to 600 px and the height to 400 px. Also, I think that the framerate should not be below 20 fps.
ii. Draw a rectangle with your Rectangle Tool (R). If you feel like it, you can make it resemble an adverstiment of some kind.
iii. Convert it to a Movieclip (F8), call it advertisment_mc (this is not necessary, but advisible) and give it an instance name ad ( this is necessary).
| [ type the instance name here ] |
|
iv. Then, double-click on it to work inside it.
v. Create another layer inside ( call it cancel-button) and draw a small circle on it that will represent the cancel-button of our ad. Also, we need to convert the circle to a Movieclip (call it cancel-button) and give it an istance name button.
| [this is how your layers may look ] |
|
vi. Go back to the Main Timeline (click on the back-arrow).
vii. Select the ad and press F9 for Actionscript window to appear. Paste there the following code:
- onClipEvent (enterFrame) {
- distance = Math.sqrt(Math.pow(_root.ad.button._y-_root.ad._ymouse, 2)+Math.pow(_root.ad.button._x-_root.ad._xmouse, 2));
- if (distance<30 && _root.ad._xmouse<_root.ad.button._x) {
- _root.ad._x += (40-distance)/2;
- }
- if (distance<30 && _root.ad._xmouse>_root.ad.button._x) {
- _root.ad._x -= (40-distance)/2;
- }
- _root.ad.button.onPress = function() {
- _root.ad._visible = false;
- };
- }
That's quite a code, isn't it? But don't be afraid - if you've got some basic understanding of Actionscript, you should gasp the code in no time!
On the next page, you're going to find out why the above code works.