简体   繁体   中英

actionscript 3 how to use getChildByName for button (not MovieClip)

okay so I have a button (not a movie clip) called sClose. I also have a button called s and a movieclip called sMC. Basically, everything is on one frame. The code starts off by making sMC hidden and sClose hidden. Now, when you click s, sMC and sClose appear. SMC is a screen and sClose is just a close button, where if you click it, then it hides itself and it hides sMC. So basically, if sCLose is clicked, it takes you back to the original screen. Here is the actionscript 3 cpde.

sMC.visible=false;
sCLose.visible=false;
s.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
    var focus;
    var cB;
    focus = MovieCLip(getChildByName(event.target.name + "MC"));
    cB = Button(getChildByName(event.target.name + "Close"));
    focus.visible=true;
    cB.visible=true;

When I run the code, there is no error for the MovieClip(getChildByName) line, however, it gives an error for the Button(getChildByName) line. It says "Call to possibly undefined method Button." Why is it saying this?

You don't really need to cast it to anything except DisplayObject. You don't use any of Button's properties so if you write

cB = DisplayObject(getChildByName(event.target.name + "Close"));
cB.visible=true;

it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM