This site is optimised for Firefox 2.0 or Internet Explorer 7.

as3 - simple random latin text class

kheavy has no avatar
kheavy
 
Post Count: 106
Joined: Fri Jul 21, 2006 1:22 pm
Location: charlotte, nc

as3 - simple random latin text class

Postby kheavy on Wed Feb 13, 2008 11:49 pm

when designing dynamic sites with future data to be loaded from XML files (or some other dynamic source) - i often use this class to get dummy text before i code it to pull in the real text from the final source. this lets me prototype quickly and fake up what real content may look like before i ever have it - or want to spend the energy to connect to it :)

Code: Select all
package com.nudoru.utils {
   
   public class RandomLatin {
      
      private var LatinText:Array = ["Lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "praesent",
                 "vel", "nibh", "vel", "wisi", "molestie", "placerat", "nunc", "amet","libero", "in",
                 "turpis", "facilisis", "tempor", "Sed", "blandit", "quis", "consequat", "molestie",
                 "orci", "neque", "tincidunt", "nisl", "in", "elementum", "tortor", "vitae", "est",
                 "Donec", "sapien", "Aenean", "eleifend", "purus", "vel", "praesent", "ultricies",
                 "fringilla", "massa", "Etiam", "pede", "sed", "felis", "ac", "ante", "venenatis",
                 "porta", "nullam", "orci", "In", "quis", "diam", "mattis", "augue", "varius"];
      
      public function RandomLatin():void {
         //
      }
      
      public function generateLatinString(s:String):String {
         var a:Array = s.split(":");
         var min:int = int(a[1].split(",")[0]);
         var max:int = int(a[1].split(",")[1]);
         return getLatinText(min,max);
      }
      
      public function getLatinText(minl:int, maxl:int):String {
         var len:int = rnd(minl, maxl);
         var s:String = "";
         for(var i:int=0; i<len; i++) {
            var t:String = LatinText[Math.floor(Math.random()*LatinText.length)].toLowerCase();
            if(i<=len) t+=" ";
            if(i == 0) {
               var a:String = t.charAt(0).toUpperCase();
               var b:String = t.substr(1);
               t = a+b;
            }
            s+=t;
         }
         return s;
      }
      
      public function rnd(min:int, max:int):int {
         return min + Math.floor(Math.random() * (max + 1 - min));
      }
      
   }
}


usage:
Code: Select all
import com.nudoru.utils.*;
var l:RandomLatin = new RandomLatin();
myMC_mc.text_txt.text = l.getLatinText(5,10);

User avatar
nebutch
Site Admin
 
Post Count: 3395
Joined: Wed Apr 05, 2006 12:36 am
Location: Earth, Milky Way
Flash Version: Adobe Flash CS4

Re: as3 - simple random latin text class

Postby nebutch on Thu Feb 14, 2008 6:22 am

Very nice! Thanks for sharing, kheavy!
Trust me, I know what I'm doing...

Image

Did this post help? If so, please consider a donation! Just click the "Donate" link at the top-right of this page.

utopastac has no avatar
utopastac
 
Post Count: 109
Joined: Fri Oct 19, 2007 4:40 pm

Re: as3 - simple random latin text class

Postby utopastac on Thu Feb 14, 2008 9:23 am

It's cool, but I don't feel like it's the kind of thing I'd want to instantiate, rather just have it as a static function somewhere. I may abuse it for my purposes. ;)

kheavy has no avatar
kheavy
 
Post Count: 106
Joined: Fri Jul 21, 2006 1:22 pm
Location: charlotte, nc

Re: as3 - simple random latin text class

Postby kheavy on Thu Feb 14, 2008 12:03 pm

thanks! abuse away! if you do something nice with it, post it back here, i might want to use it too :)


Return to Shared User Content

Who is online

Users browsing this forum: No registered users and 1 guest