Monthly Archives: October 2008

MovieClip Random Frame

Actionscript:
  1. myClip.gotoAndStop(int(Math.random() * myClip.totalFrames + 1));

An easy way to make a MovieClip go to a random frame. In the future I may post a demo of this technique.

Posted in MovieClip, random | Leave a comment

Quick Alphabet Array

Actionscript:
  1. var alphabet:Array = ("abcdefghijklmnopqrstuvwxyz").split("");
  2. trace("this is the letter b...", alphabet[1]);
  3. trace(alphabet);
  4. /* outputs:
  5. this is the letter b... b
  6. a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
  7. */

This is an easy way to create an array of the alphabet. It's easier to type than:

Actionscript:
  1. var alphabet:Array = ["a","b","c".... etc];

Posted in arrays, string manipulation, strings | 3 Comments

Function Returns a Function

Actionscript:
  1. appendExclamation("actionsnippit")("dot")("com")("is")("live");
  2.  
  3. function appendExclamation(str:String):Function{
  4.   trace(str + "! ");
  5.   return appendExclamation;
  6. }
  7.  
  8. /* outputs:
  9. actionsnippit!
  10. dot!
  11. com!
  12. is!
  13. live!
  14. */

This technique allows you to call a function more than once on one line. I first saw this used in the source files from a talk at flashcoders ny... I didn't attend the talk, but stumbled on this interesting blog post awhile back http://www.flashcodersny.org/wordpress/?p=166.

This is a fun technique to use, I've found some unusual uses for it already... some of which you'll see in later posts....

Posted in functions, return values | Comments closed