键盘/文本框的帮助下互动,请 [英] interaction with keyboard/textfields help please

查看:134
本文介绍了键盘/文本框的帮助下互动,请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常为一个字符串对象转换如下:

Normally for a string to object is converted as follows.

var obj:object=getChildByName("string");

和我们可以给属性像 obj.x = 100; 但是,在一系列蜇伤的情况下

And we can give properties to it like obj.x=100;But in the case of a series of stings

[objet Stage].[object MainTimeline].[object TextField]

该宏将会不works.Actually我需要给物业一个目标路径是一个字符串 我做的事?? 这里是code得到路径一个影片剪辑:

it wil not works.Actually i need to give properties to a target path which is a string what i do?? Here is the code to get path to a movieclip:

 addEventListener(MouseEvent.CLICK, targetMC);
function targetMC(MouseEvent:Event):void
{
 var curinstance = MouseEvent.target.valueOf();
 var targ:Object = curinstance.parent;
 var path = curinstance;
 do
 {
  if (targ == "[object Stage]")
  {
   path = targ + "." + path;
  }
  else
  {

   path = targ + "." + path;
  }

  targ = targ.parent;
 } while (targ);


 trace(path);

}

我想给属性路径

推荐答案

许多事情是尴尬的你code:

A number of things are awkward about your code:

  1. 不要比较对象的字符串值,以了解类的类型。使用关键字:

if (obj.parent is Stage) doSomething();

  • 不要使用类名作为参数名称:!的MouseEvent是一种

  • Don't use class names as parameter names: MouseEvent is a type!

    function targetMC ( ev:MouseEvent ) // ...more code
    

  • 它根据在调用它们的事件是非常有用的名字处理方法,例如:

  • It is useful to name handler methods according to the event upon which they are invoked, for example:

    function onMouseClick (ev:MouseEvent) 
    

    function mouseClickHandler (ev:MouseEvent) 
    

  • 如果你能避免它,不要转换为对象来访问成员,但尝试使用子类型 - 它可以让编译器能够更有效地检查您的code错误。由于显示列表中的所有对象均的DisplayObject 的情况下,你可以使用这样的:

  • If you can avoid it, don't cast to Object 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 DisplayObject, you could use this:

    var obj:DisplayObject = ev.target as DisplayObject;
    

  • 如果要输出的路径,你的对象,用实例名称,而不是类型 - !你可能有多个文本字段

  • If you want to output a path to your object, use instance names instead of types - you might have more than one TextField!

    private function getObjectPath (obj:DisplayObject) : String {
        var path:String = obj.name;
        if (obj.parent != null && !(obj.parent is Stage)) {
            path = getObjectPath (obj.parent) + "." + path;
        }
        return path;
    }
    

  • 现在你的答案:使用的KeyboardEvent

    Now for your answer: Use the KeyboardEvent.

    textField.addEventListener (KeyboardEvent.KEY_UP, onKeyUp);
    

    private function onKeyUp (ev:KeyboardEvent) : void {
        var tf:TextField = ev.target as TextField;
        var text:String = tf.text;
        tf.text = text + String.fromCharCode(charCode);
    } 
    

    请注意,这只会只要文本字段有焦点的工作,那就是用户必须先点击它。

    Note that this will only work as long as the TextField has focus, that is the user has to click it first.

    这篇关于键盘/文本框的帮助下互动,请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆