Posted By

todbertuzzi on 01/11/08


Tagged

text builder


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

crashdr


TextBuilder


 / Published in: ActionScript
 

esemio1: (vengono utilizzati un pò tutti i parametri) var myString:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat."; var myClip:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth()); TextBuilder.ShowText(myClip, true, 500, myString, "#333333", "verdana", 10, false, 60, Quart.easeOut, false, {myLeading:5, myAlign:"right", myBackground:"0xCCCCCC", mySelectable:true, myBorder:true}, myCallbackFunction, myClip, [15, "i'm a string", false]); function myCallbackFunction(myNumber:Number, myString:String, myBoolean:Boolean) { trace("myNumber: "+myNumber); trace("myString: "+myString); trace("myBoolean: "+myBoolean); trace("validity: "+this); }

//esempio 2 (standard) var myString:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat."; var myClip:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth()); TextBuilder.ShowText(myClip, true, 500, myString, "#333333", "verdana", 10, false, 60, Quart.easeOut, false, null, myCallbackFunction, myClip, [15, "i'm a string", false]); function myCallbackFunction(myNumber:Number, myString:String, myBoolean:Boolean) { trace("myNumber: "+myNumber); trace("myString: "+myString); trace("myBoolean: "+myBoolean); trace("validity: "+this); }

  1. class TextBuilder {
  2.  
  3. public static function ShowText(mc:MovieClip, direction:Boolean, wdt:Number, s:String,myColor:String, myFont:String, mySize:Number, myEmbed:Boolean, speed:Number, method:Function, alphaTrans:Boolean, myExtra:Object, callBack:Function, validity:MovieClip, param:Array){
  4.  
  5. if(!mc.TextBuilderEnterClip) mc.clipEnter=mc.createEmptyMovieClip("TextBuilderEnterClip",mc.getNextHighestDepth());
  6.  
  7. mc.myText=mc.createTextField("dynText", 1, 0, 0, wdt, 1);
  8. wdt ? (mc.myText.multiline = true, mc.myText.wordWrap = true) : (mc.myText.multiline = false,mc.myText.wordWrap = false);
  9. mc.myAlign = myExtra.myAlign ? myExtra.myAlign : "left";
  10. mc.myLeading = myExtra.myLeading ? myExtra.myLeading : 0;
  11. myExtra.myBackground ? ( mc.myText.background = true, mc.myText.backgroundColor = myExtra.myBackground ) : mc.myText.background = false;
  12. myExtra.mySelectable ? mc.myText.selectable = true : mc.myText.selectable = false;
  13. myExtra.myBorder ? mc.myText.border = true : mc.myText.border = false;
  14. mc.myText.html = true;
  15. mc.myText.antiAliasType="advanced"
  16. mc.myText.embedFonts = myEmbed;
  17. mc.myText.autoSize = "left";
  18.  
  19. mc.clipEnter.t=0;
  20. mc.clipEnter.d=speed;
  21. mc.clipEnter.s=0;
  22. mc.clipEnter.e=s.length;
  23. mc.clipEnter.st=s;
  24. mc.clipEnter.myDirection=direction;
  25. mc.clipEnter.transAlpha=alphaTrans;
  26. mc.clipEnter.sa=mc._alpha;
  27. mc.clipEnter.ea=100;
  28. mc.firstHalfString="<TEXTFORMAT LEADING=\""+mc.myLeading+"\"><P ALIGN=\""+mc.myAlign+"\"><FONT FACE=\""+myFont+"\" SIZE=\""+mySize+"\" COLOR=\""+myColor+"\">"
  29. mc.secondHalfString="</FONT></P></TEXTFORMAT>";
  30.  
  31. mc.clipEnter.onEnterFrame=function(){
  32. if (this.t++<this.d){
  33. if(this.transAlpha)mc._alpha=Math.round(method(this.t,this.sa,this.ea,this.d));
  34. if(this.myDirection){
  35. mc.myText.htmlText=mc.firstHalfString+this.st.substr(-Math.round(method(this.t,this.s,this.e,this.d)),Math.round(method(this.t,this.s,this.e,this.d)))+mc.secondHalfString;
  36. this.tempString=this.st.substr(-Math.round(method(this.t,this.s,this.e,this.d)),Math.round(method(this.t,this.s,this.e,this.d)));
  37. } else {
  38. mc.myText.htmlText=mc.firstHalfString+this.st.substr(0,Math.round(method(this.t,this.s,this.e,this.d)))+mc.secondHalfString;
  39. this.tempString=this.st.substr(0,Math.round(method(this.t,this.s,this.e,this.d)));
  40. }
  41. } else {
  42. this.onEnterFrame=undefined;
  43. callBack.apply(validity,param);
  44. }
  45. }
  46. }
  47.  
  48. public static function HideText(mc:MovieClip, direction:Boolean, speed:Number, method:Function, alphaTrans:Boolean, callBack:Function, validity:MovieClip, param:Array){
  49.  
  50. mc.clipEnter.t=0;
  51. mc.clipEnter.d=speed;
  52. mc.clipEnter.s=mc.clipEnter.tempString.length;
  53. mc.clipEnter.e=-mc.clipEnter.tempString.length;
  54. mc.clipEnter.myDirection=direction;
  55. mc.clipEnter.transAlpha=alphaTrans;
  56. mc.clipEnter.sa=mc._alpha;
  57. mc.clipEnter.ea=-mc._alpha;
  58. mc.clipEnter.onEnterFrame=function(){
  59. if (this.t++<this.d){
  60. if(this.transAlpha)mc._alpha=Math.round(method(this.t,this.sa,this.ea,this.d));
  61. if(this.myDirection){
  62. mc.myText.htmlText=mc.firstHalfString+this.tempString.substr(-Math.round(method(this.t,this.s,this.e,this.d)),Math.round(method(this.t,this.s,this.e,this.d)))+mc.secondHalfString;
  63. this.tempString=this.st.substr(-Math.round(method(this.t,this.s,this.e,this.d)),Math.round(method(this.t,this.s,this.e,this.d)));
  64. } else {
  65. mc.myText.htmlText=mc.firstHalfString+this.tempString.substr(0,Math.round(method(this.t,this.s,this.e,this.d)))+mc.secondHalfString;
  66. this.tempString=this.st.substr(0,Math.round(method(this.t,this.s,this.e,this.d)));
  67. }
  68. } else {
  69. this.onEnterFrame=undefined;
  70. callBack.apply(validity, param);
  71. }
  72. }
  73. }
  74.  
  75. public static function MadeText(mc:MovieClip, wdt:Number, s:String, myColor:String, myFont:String, mySize:Number, myEmbed:Boolean , myExtra:Object){
  76.  
  77. mc.myAlign = myExtra.myAlign ? myExtra.myAlign : "left";
  78. mc.myLeading = myExtra.tLeading ? myExtra.myLeading : 0;
  79.  
  80. mc.myText=mc.createTextField("dynText", 1, 0, 0, wdt, 1);
  81. wdt ? (mc.myText.multiline = true, mc.myText.wordWrap = true) : (mc.myText.multiline = false,mc.myText.wordWrap = false);
  82. myExtra.myBackground ? ( mc.myText.background = true, mc.myText.backgroundColor = myExtra.myBackground ) : mc.myText.background = false;
  83. myExtra.mySelectable ? mc.myText.selectable = true : mc.myText.selectable = false;
  84. myExtra.myBorder ? mc.myText.border = true : mc.myText.border = false;
  85. mc.myText.html = true;
  86. mc.myText.antiAliasType="advanced";
  87. mc.myText.embedFonts = myEmbed;
  88. mc.myText.autoSize = "left";
  89. mc.firstHalfString="<TEXTFORMAT LEADING=\""+mc.myLeading+"\"><P ALIGN=\""+mc.myAlign+"\"><FONT FACE=\""+myFont+"\" SIZE=\""+mySize+"\" COLOR=\""+myColor+"\">"
  90. mc.secondHalfString="</FONT></P></TEXTFORMAT>";
  91. mc.myText.htmlText=mc.firstHalfString+s+mc.secondHalfString;
  92. }
  93. }

Report this snippet  

You need to login to post a comment.