When I’m writing any code I have this little internal rule: any block of code repeated more than two times becomes a function. Naturally, I end up with quite a few functions.

Needless to say , one of the first things that caught me off guard when I started rolling back into the Flash4 ActionScript .5 state of mind, was the inability to create user defined functions. UGH! So, to that end, if there is anyone else feeling my pain on this issue, I’ve slapped together a quick sample of how to overcome the lack of UDFs in Flash Lite. I hope it helps.

You can view the really simple example that’s also available for download. Let’s get to it.

My first move was to create a MovieClip on the main timeline and gave it an instance name of ‘f’. Within my MovieClip ‘f“, I inserted blank keyframes on frames 2 and 3. Each frame was given a frame label, ‘foo’ and ‘bar’, respectively. On frame 1 of the same clip, I added a stop action

Whenever I needed the code on a particular frame (either ‘foo’ or ‘bar’) to be executed I would add the following code to any given button.

on(someEvent)

{

tellTarget(’f‘)

  {

gotoAndStop(‘foo’);

}

}

While this code would work, it’s not the most elegant solution to me. Instead of using the tellTarget command we could simply things a bit by using the AS.5 keyword call

Now, the same code above would be:

on(someEvent)

{

call(’/f:foo’);

}

Booyuh! Much cleaner and easier to read.

See attached files for samples. Remember this is designed to work with a phone so you’ll need to push the 1 & 2 buttons.