Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You receive multiple FocusEvents, because TextArea contains a TextInput that it controls. When you Focus on the TextArea, the focus is actually given to the TextInput and you receive a focus event for the TextArea, and another for the TextInput.</p> <p>The best way to limit the number of received event is to check if the target of the event is the same that the target you actually listen.</p> <pre><code>function onFocusIn(event:FocusEvent):void{ if (event.target == event.currentTarget) { trace(event.target); // only the focus events generated by the TextArea. } } </code></pre> <p><strong>EDIT</strong> So, I got back to the code with the issue about clicks, and the actual fix is really tricky. In fact, the source of the error was a combination of various same issues.</p> <ul> <li>First : the fact that TextArea and the inner TextField both send Event at the beginning.</li> <li>Second : After the beginning, when the TextField receive focus from a click, it is blocked by the parent.</li> <li>And Third : When the focus come from out of the swf, in your case, the focus event is send two times (dunno why).</li> </ul> <p>In order to fix it correctly, I had to listen to the unknown TextField within the TextArea (instead of the TextArea itself), and keep track of the focus leaving the Stage in order to inhibit the first of the two events generated. Which gives this : </p> <pre><code>import flash.events.FocusEvent; import fl.controls.TextArea; var stageFocus:Boolean = true; var field = new TextArea(); addChild(field); var field2 = new TextArea(); field2.x = 150; addChild(field2); field.addEventListener(FocusEvent.FOCUS_IN, onFocusIn); function onFocusIn(event:FocusEvent):void{ if (event.target == event.currentTarget) { if (event.target is TextField) { if (stageFocus) { // Finally ! one event at a Time and no miss. trace(DisplayObject(event.target).parent); } else { stageFocus = true; } } } else { event.target.addEventListener(FocusEvent.FOCUS_IN, onFocusIn); field.removeEventListener(FocusEvent.FOCUS_IN, onFocusIn); } } // check if the focus leave the stage (the user clic out of the swf) stage.addEventListener(FocusEvent.FOCUS_OUT, onStageFocusOut); function onStageFocusOut(event:FocusEvent) { if (event.relatedObject == null) { stageFocus = false; } } </code></pre>
    singulars
    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.
    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