代码之家  ›  专栏  ›  技术社区  ›  john

我如何用面向对象的方法编写这个代码

  •  0
  • john  · 技术社区  · 14 年前

    我有一个按钮叫 profile_btn

    我想用面向对象的方法来编写这个代码。

    profile_btn.addEventListener(MouseEvent.CLICK,profile_btnClickHandler);
    function profile_btnClickHandler(ev:MouseEvent):void
    {
        //The actual code to jump to a specific frame
        this.gotoAndPlay('play');
    }
    

    1 回复  |  直到 11 年前
        1
  •  0
  •   loxxy    14 年前

    如果您有一个类(您在linkage中指定的名称)profile\u btn,则可以使用以下命令。

    var myButton:profile_btn =new profile_btn()
    

    stage.addChild(myButton);
    

    所以你的代码看起来像

    var myButton:profile_btn =new profile_btn()
    
    stage.addChild(myButton);
    
    myButton.addEventListener(MouseEvent.CLICK,profile_btnClickHandler);
    
    function profile_btnClickHandler(ev:MouseEvent):void
    {
        //The actual code to jump to a specific frame
        this.gotoAndPlay('play');
    }