Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A number of things are awkward about your code:</p> <ol> <li><p>Don't compare the string value of objects to find out about class type. Use the <code>is</code> keyword:</p> <pre><code>if (obj.parent is Stage) doSomething(); </code></pre></li> <li><p>Don't use class names as parameter names: MouseEvent is a type!</p> <pre><code>function targetMC ( ev:MouseEvent ) // ...more code </code></pre></li> <li><p>It is useful to name handler methods according to the event upon which they are invoked, for example:</p> <pre><code>function onMouseClick (ev:MouseEvent) </code></pre> <p>or </p> <pre><code>function mouseClickHandler (ev:MouseEvent) </code></pre></li> <li><p>If you can avoid it, don't cast to <code>Object</code> to access members, but try to use subclass types - it allows the compiler to more effectively check your code for errors. Since all objects in the display list are instances of <code>DisplayObject</code>, you could use this:</p> <pre><code>var obj:DisplayObject = ev.target as DisplayObject; </code></pre></li> <li><p>If you want to output a path to your object, use instance names instead of types - you might have more than one TextField!</p> <pre><code>private function getObjectPath (obj:DisplayObject) : String { var path:String = obj.name; if (obj.parent != null &amp;&amp; !(obj.parent is Stage)) { path = getObjectPath (obj.parent) + "." + path; } return path; } </code></pre></li> </ol> <p>Now for your answer: Use the KeyboardEvent.</p> <pre><code>textField.addEventListener (KeyboardEvent.KEY_UP, onKeyUp); </code></pre> <p>and</p> <pre><code>private function onKeyUp (ev:KeyboardEvent) : void { var tf:TextField = ev.target as TextField; var text:String = tf.text; tf.text = text + String.fromCharCode(charCode); } </code></pre> <p>Note that this will only work as long as the TextField has focus, that is the user has to click it first.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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