How to add smiley to chat application using Action Script 3 in Flash Professional
This may be simple task when someone give you this, But really some what difficult is there while positioning smiley in the textfield. I had gone through Google none of them explained this.
Download sample files here.
Here is simple way I had tried to position the smiley in chat application at exact position, may it useful to you guys. Try this and let me know if you have any ideas about smiley positioning.
In this tutorial I getting text and smiley we had entered in the textbox and save it in a string variable. Then using split() method I split-ed that string into text and smiley and saved it in array variable. Now you can get text and smiley separately using array index like.
str1[0]= hi every body
str1[1]=<img src=’eye.jpg’ vspace=’-20′ height=’40’ width=’40’/>
Now I added this ‘str1[0]= hi every body‘ in the TextField to know width of text to position the smiley in after the text. Then adjusting vspace and hspace property of img tag I positioned smiley at exact position.
To know various techniques for finding text width of TextField refer my previous tutorial ‘how to find text width of TextField using ActionScript 3 in Flash professional’
package { import flash.text.TextField; import flash.display.MovieClip; import flash.text.TextFormat; public class SmileyText extends MovieClip { public function SmileyText() { var txt:TextField= new TextField; var txt1:TextField= new TextField; var txt_format:TextFormat=new TextFormat; txt_format.font='Verdana'; txt_format.size='15'; var str:String="hi every body <img src='eye.jpg' vspace='-20' height='40' width='40'/>"; var str1=str.split('<img'); txt1.defaultTextFormat=txt_format; txt1.text=str1[0]; var txt_width=txt1.textWidth; var str2:String="hi every body <img src='eye.jpg' vspace='-20' hspace='"+txt_width+"' height='40' width='40'/>"; txt.defaultTextFormat=txt_format; txt.width=200; txt.htmlText=str2; addChild(txt); } } }
Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts
If you want any of my script need to be customized according to your business requirement,
Please feel free to contact me [at] muni2explore[at]gmail.com
Note: But it will be charged based on your customization requirement