Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I solved my own problem using <code>background</code> and <code>border</code> properties from TextField. Instead of create TextField directly on my MovieClip, I create it dynamically.</p> <pre><code>// Field 'Name' of the layer var tarea:TextField = new TextField(); tarea.text = 'Layer'; tarea.x = -80; tarea.y = -23; tarea.type = TextFieldType.DYNAMIC; tarea.height = 20; // Format the TextField var format_tarea:TextFormat = new TextFormat(); format_tarea.font = "Arial"; format_tarea.size = 14; format_tarea.bold = true; tarea.setTextFormat(format_tarea,0,tarea.length); </code></pre> <p>Then, I add it some listeners to allow changes when I click on it:</p> <pre><code>// Add event to allow name changes tarea.addEventListener(MouseEvent.CLICK,changeName); </code></pre> <p>When I press ENTER key, I accept the changes</p> <pre><code>// Add event to accept changes on press ENTER key tarea.addEventListener(KeyboardEvent.KEY_DOWN,acceptKeyboardName); </code></pre> <p>When TextField lost his focus, accept the changes too:</p> <pre><code>tarea.addEventListener(FocusEvent.FOCUS_OUT,acceptFocusName); </code></pre> <p>Last, I added to my own MovieClip</p> <pre><code>// Add to MC mc.addChild(tarea); </code></pre> <p>Handlers associated to below events are these:</p> <pre><code>private function changeName(e:MouseEvent):void { e.target.setSelection(0,e.target.text.length); e.target.border = true; e.target.background = true; e.target.type = TextFieldType.INPUT; } private function acceptKeyboardName(e:KeyboardEvent):void { if (e.charCode == 13) // When pres ENTER, remove border, background and restore dynamic type { e.target.type = TextFieldType.DYNAMIC; e.target.border = false; e.target.background = false; } } private function acceptFocusName(e:FocusEvent):void { // When lost focus, remove border, background and restore dynamic type e.target.type = TextFieldType.DYNAMIC; e.target.border = false; e.target.background = false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload