Flash 自动将舞台上的对象命名为“实例#”
我的主舞台上已经放置了 2 个 TLF 文本框。在属性检查器窗口中,我为它们指定了实例名称:“txt1”和“txt2”。
我试图有一个 mouseup 事件,并找出它发生在哪个文本框上。
我的文档类具有以下代码:
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
public class SingleEvent extends Sprite{
public function SingleEvent() {
// constructor code
root.addEventListener(KeyboardEvent.KEY_UP, textChanged,false,0,true);
}
private function textChanged(e:KeyboardEvent){
trace(e.target.name);
trace(" " + e.target);
switch(e.target){
case txt1:
trace("txt1 is active");
break;
case txt2:
trace("txt2 is active");
break;
default:
break;
}
}
}
}
示例输出为:
instance15
[object Sprite]
instance21
[object Sprite]
由于对象已经在舞台上,我不确定如何让 flash 将它们识别为“txt1”和“txt2”而不是“instance#”。我尝试设置 .name 属性,但没有效果。
在发布设置中,我选中了“自动声明阶段实例”。
另外,是否可以为多个滑块组件提供一个更改事件?以下永远不会触发:
root.addEventListener(SliderEvent.CHANGE, sliderChanged,false,0,true);
感谢您的任何提示
I have 2 TLF text boxes already placed on my main stage. In the property inspector window I give these the instance names: "txt1" and "txt2".
I am trying to have a single mouseup event, and figure out which text box it occurred on.
My document class has the following code:
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
public class SingleEvent extends Sprite{
public function SingleEvent() {
// constructor code
root.addEventListener(KeyboardEvent.KEY_UP, textChanged,false,0,true);
}
private function textChanged(e:KeyboardEvent){
trace(e.target.name);
trace(" " + e.target);
switch(e.target){
case txt1:
trace("txt1 is active");
break;
case txt2:
trace("txt2 is active");
break;
default:
break;
}
}
}
}
Example output is:
instance15
[object Sprite]
instance21
[object Sprite]
Since the objects are already on the stage, I am not sure how to get flash to recognize them as "txt1" and "txt2" instead of "instance#". I tried setting the .name property, but it had no effect.
In the publish settings, I have "Automatically declare stage instances" checked.
Also, is it possible to have a single change event for multiple slider components? The following never fires:
root.addEventListener(SliderEvent.CHANGE, sliderChanged,false,0,true);
Thanks for any tips
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调用构造函数时,Flash Player 似乎尚未初始化 TLFTextFields。试试这个:
您会发现除了神秘创建的附加对象“__id#”和“instance#”之外,您的两个 TFLTextField 都被识别。
另外,您的 Slider 组件显然不会“冒泡”其 SliderEvents,这意味着它们永远不会到达根对象。但是,您可以根据需要多次分配处理程序函数,因此您只需向每个滑块添加侦听器,所有侦听器都引用相同的
sliderChanged
函数。It seems that the Flash Player hasn't initialized the TLFTextFields by the time the constructor is called. Try this:
You will find that in addition to the mysteriously created additional objects "__id#" and "instance#", both of your TFLTextFields are recognized.
Also, your Slider components obviously don't "bubble" their SliderEvents, which means they never reach the root object. You can, however assign a handler function as many times as you want, so you could just add listeners to each of your sliders, all referring to the same
sliderChanged
function.