A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Smiley TextField component

  1. #1
    Junior Member
    Join Date
    Jan 2002

    Smiley TextField component

    Hi guys

    I developed a textfield component with smiley management.
    Here is an example of its use in a larger Flash application :

    Before giving it away and opening the source, I'd like to get some guarantee about how to prevent people for using it in a commercial application.
    Does anyone have some advice on the public license one should use to release a Flash component ?

    Cheers, jolan
    - jolan -

  2. #2
    Senior Member
    Join Date
    Oct 2001
    wow... thats pretty sweet... howd you do it???

  3. #3
    Junior Member
    Join Date
    Jan 2002
    Component Parameters and default values

    // Calculate the number of lines to match the component height ?
    this._linesMatchHeight = true;
    // If the previous parameter is set to false, set the custom number of lines
    this._numLines = 10;
    	// Text formatting
    this._font = "Verdana";
    this._size = 11;
    this._leftMargin = 0;
    this._rightMargin = 0;
    this._leading = 6;
    // Textfield border properties
    this._border = true;
    this._borderColor = "0x000000";
    // Textfield background properties
    this._background = true;
    this._backgroundColor = "0x000000";
    // Font embedding
    this._embedFonts = false;
    // Smiley activation
    this._smiActive = true;
    // Smiley animation
    this._smiAnim = true;
    Here is the list of the methods of the SmileyTextfield class :

    #initclip 1
    SmileyTextFieldClass = function(name, level, x, y, width, height) { ... };
    SmileyTextFieldClass.prototype = new MovieClip;
    Object.registerClass("Jolan_SmileyTextFieldSymbol", SmileyTextFieldClass);
    SmileyTextFieldClass.prototype.init = function() { ... };
    /* ***** PUBLIC METHODS ****** */
    // [:INFO:] setSize function
    // Resize the component
    SmileyTextFieldClass.prototype.setSize = function(w, h) { ... };
    // [:INFO:] clearText function
    // Clears the textfield, removes the smilies and resets variables and arrays
    SmileyTextFieldClass.prototype.clearText = function() { ... };
    // [:INFO:] parseString function
    // Parses a string for smileys and HTML tags and displays it
    SmileyTextFieldClass.prototype.parseString = function(str, clearFlag, beginIndex, endIndex) { ... };
    /* ***** PRIVATE METHODS ***** */
    // [:INFO:] createCharWidthMap function
    // Retrieves the width for each character of the set
    SmileyTextFieldClass.prototype.createCharWidthMap = function(text_fmt, embedFonts_flag, chr_start, chr_end) { ... };
    // [:INFO:] updatePixelPos function
    // Updates the horizontal position of the cursor by adding the width of the current character
    // Returns true and resets variables if a newline is detected, false otherwise
    SmileyTextFieldClass.prototype.updatePixelPos = function(string, pos, i) { ... };
    // [:INFO:] parseHtmlShortcuts function
    // Parses the string for HTML shortcuts ( , >...) starting at the specified character
    // Replaces the shortcut by the corresponding ASCII character and returns the new position in the string 
    SmileyTextFieldClass.prototype.parseHtmlShortcuts = function(i) { ... };
    // [:INFO:] parseTags function
    // Parses the string for HTML tags (<b>, <a>...) starting at the specified character
    // Updates this.is_bold variable if needed and returns the new position in the string 
    SmileyTextFieldClass.prototype.parseTags = function(i) { ... };
    // [:INFO:] attachSmiley function
    // Attaches a smiley movieclip to the stage and returns its name 
    SmileyTextFieldClass.prototype.attachSmiley = function(smi_obj, x, new_line) { .. };
    // [:INFO:] setSmileyVerticalPos function
    // Sets the vertical line position of a smiley to match the corresponding line of text
    SmileyTextFieldClass.prototype.setSmileyVerticalPos = function(smiley, new_line) { ... };
    // [:INFO:] updateSmileyLines function
    // Attachs, repositions or removes smileys to match the current scrolling position in the textfield
    SmileyTextFieldClass.prototype.updateSmileyLines = function() { ... };
    // [:INFO:] parseSmileys function
    // Parses the string for smileys, and adds in the smiley array the infos for the smileys found
    SmileyTextFieldClass.prototype.parseSmileys = function(i) { ... };
    Basically, I first create an multi-dimensional array containing the width of each character in the set according to the text formatting options (font face and size), then there's a great deal of parsing, during which global values specifying the position in the string, the total width of the chunk of string already parsed...
    This is a tricky part because you have to avoid updating the width when parsing HTML tags, to transform the classic HTML shortcuts (like "& nbsp ;") into their actual character display (a space character for "& nbsp ;" ) to retrieve the correct width...
    When a smiley shortcut is reached in a string, it is replaced by space characters and the corresponding smiley is added to the display.
    Then you have to manage all the different cases for carriage return, and when you mastered this, you still have to find a way to fix some font display problems (device fonts in an HTML textfield are not always of a fixed size depending on some constraints like spaces surrounding the string, etc...)

    Hope that explained some things Must seem pretty opaque from the outside, it will seem much easier when released in open source !

    Cheers, jolan
    - jolan -

  4. #4
    Junior Member
    Join Date
    Sep 2001
    I have a little problem with the component
    I`ve tried to use it and all goes ok ,text appears ok , but the smileyes appear in the upper left corner
    I`ve sent you an email in this matter.

    Can you make here an "how to use smileytextfield"? Because it`s a very interesting and usefull component.
    Thank You !
    on (release){
    gotoAndPlay("squish brains out"){

  5. #5
    Senior Member catapop's Avatar
    Join Date
    Nov 2005
    probably because you compiled for flash player 7 or 8! you must compile the fla for flash player 6

  6. #6
    Senior Member catapop's Avatar
    Join Date
    Nov 2005
    can anyone have this commponent running ok on flash 8??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center