I don't see the TexField

I don't understand where i wrong.. 
I have this class:
package myComponents
          import flash.display.Sprite;
          import flash.events.MouseEvent;
          import flash.text.TextField;
          import flash.text.TextFieldType;
          public class TextField_caretIndex extends Sprite
                              public function TextField_caretIndex()
                                        var tf:TextField = createCustomTextField(10, 10, 100, 100);
                                        tf.wordWrap = true;
                                        tf.text = "Click in this text field. Compare the difference between clicking without selecting versus clicking and selecting text.";
                                        //tf.addEventListener(MouseEvent.CLICK, printCursorPosition);
                              private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
                                        var result:TextField = new TextField();
                                        result.x = x;
                                        result.y = y;
                                        result.width = width;
                                        result.height = height;
                                        addChild(result);
                                        return result;
And i call it in this way:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                                 xmlns:s="library://ns.adobe.com/flex/spark"
                                 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
          <fx:Declarations>
                    <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          <fx:Script>
                    <![CDATA[
                              import myComponents.TextField_caretIndex;
                              public function init():void
                                        var lb:TextField_caretIndex = new TextField_caretIndex();
                    ]]>
          </fx:Script>
</s:Application>
But it doesn't works.. I don't see textfield

TextField_caretIndex must implement the IVisualElement interface to be added to Flex components. Instead of extending Sprite, TextField_caretIndex should extend SpriteVisualElement or UIComponent class. In your init() method, you also have to add the component with the addElement() method. Alternatively, you can create TextField_caretIndex element using just MXML.

Similar Messages

Maybe you are looking for