动作如何使用getChildByName获得实例的名称 [英] Actionscript how to get name of instance using getChildByName

查看:880
本文介绍了动作如何使用getChildByName获得实例的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我有一个影片剪辑名为SC和需要写一个code其中,如果单击按钮(SC),那么会的sC dissapear。该功能需要为多个按钮。我想是

Okay so I have a MovieClip called sC and need to write a code where, if you click the button (sC) then sC will dissapear. The function needs to work for multiple buttons. What I tried was

sC.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
    var self;
    self = MovieClip(getChildByName(event.target.name));
    self.visible=false;

现在,当我尝试这个code,它给了我一个错误,当我点击资深大律师。它说:无法访​​问空对象引用的属性或方法。当我尝试跟踪(个体经营)输出空。有没有一种方法,我可以得到它是使用函数clickhandler功能,然后将对象的实例的名称使这的可见性等于假(可见=假)?

Now when I try this code, it gives me an error when I click sC. It says "cannot access a property or method of a null object reference.". when I try to trace(self) it outputs "null". Is there a way where I can get the name of the instance of the object which is using the clicKHandler function and then make it's visibilty equal to false (visible=false)?

请注意,当我跟踪(event.target.name)它说:instance127。

Note that when I trace(event.target.name) it says "instance127".

推荐答案

在你的code,变量解析为影片剪辑的名字,而不是完整路径到它的存在。尝试设置它像以下,其中目标是被点击的按钮:

In your code, the variable self resolves to your movieClip's name, but not the complete path to where it exists. Try setting it up like below, where target is the button that was clicked:

sC.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void
{
    event.target.visible = false;
}

这篇关于动作如何使用getChildByName获得实例的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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