Subscribe to RSS
get email updates
home | about | pixDif AIR app | video tutorials
polyGeek.com

Register for 360Flex in DC using the ad below and you will automatically be entered in a drawing for a free ticket. Read more.
place your ad here

Web Premium





Practical jokes to play on Flash designers – randomize _x, _y position

July 5th, 2007 . by polyGeek

You know how designers are so particular about placing assets just right? Have you seen them zoom in on the stage, select a MovieClip, and start changing it’s position by a few tenths of a pixel this way or that?

How would you like to play a little practical joke and learn some recursive code in the process?

Here’s the idea: write a function that receives a reference to a MovieClip. It takes that MovieClip and runs a for-in-loop on it looking for other MovieClips. If it finds one it passes that MovieClip back to itself – recursion. During the process it bumps all the MovieClips it finds by a few pixels this way or that, randomly.

Place this code anywhere in your friend’s/co-worker’s/victim’s FLA and give it a start by passing a reference to the _root to the recursive function.

All this happens at runtime so all those assets on the stage at authoring time will be pushed around in random directions. Madness will ensue. :-)

Here’s the code:

Here’s what the view of the stage in the Flash authoring tool. Notice that everything is lined up on the grid lines. The gray grid lines are shapes and so are not affected by the bump function.

before random bumping

Here’s the SWF after the MovieClips have been bumped around. You can download the FLA here.

The bump() function receives three arguments: a reference to the MovieClip to move, the max amount to change the _x coordinate – dx – and the max amount to change the _y coordinate – dy.

So if you want to change the amount of movement then change the parameters that are passed. I find that something like 0.5 or so for each works pretty well. Annoyance will vary depending on obviousness and the time it takes to figure out what’s going on. :-)

I take no responsibility if you get fired for playing this practical joke. As a suggestion: don’t place this code in some designer’s FLA and then go on vacation.

Perils of recursion

Recursion can be an extraordinarily powerful tool but you must handle it with care. If you are writing functions that call themselves you need to have one mantra firmly committed to memory:

Save, then publish. Save, then publish. Save, then publish.

Why, you may ask? Because there is no better way to crash a program, or computer, than writing recursive functions or methods that don’t end. That’s the real key. Making sure that you break out of the recursion.

The example here is very straight forward. But others may not be. Take for instance the Lightning class that I wrote. You don’t want to know how many times I entered into an endless loop while testing that code.

You should take at least the same precautions when writing recursive code as you do when installing a new application on your system:

  • Save everything that’s open
  • Close every application that isn’t needed
  • Always save before publishing (your mantra)
  • Wear a hazMat suit
  • Make sure your life insurance policy is up to date

Okay, those last two may be overkill but you get the idea.

Tomorrow I’ll have a variation on this idea that is just as insidious.

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

4 Responses to “Practical jokes to play on Flash designers – randomize _x, _y position”



[...] In version 1 of the practical jokes to play on Flash designers I showed how to write a recursive function that bumps all the MovieClips on the stage at authoring time around a few pixels this way or that. Version 2 of this idea is to replace all the dynamic text in an FLA at authoring time with random characters. [...]

comment number 2 by: Josh

After you freak them out once, later in the day, put that into an enterFrame loop. Every iteration, decide randomly if everything should be bumped a bit.

comment number 3 by: polyGeek

@Josh, and then you watch them from a distance and say, “Bwaaahaaahaaahaa” :-)


[...] på alle movieclips. Ikke meget, men lige akkurat nok til at frustrere din designer helt vildt: Practical jokes to play on Flash designers – randomize _x, _y position Tags: fredag, underholdning Del:These icons link to social bookmarking sites where readers can [...]

   Welcome back (Change)

Leave a Reply

comment feed RSS   subscribe to this comment thread

Recent Posts

   



polyGeek.com

© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites
Local Directory for Los Angeles, CA

Better Tag Cloud