我需要帮助“动作脚本3,带按钮的公共功能”

时间:2011-04-23 21:00:28

标签: actionscript-3

Public function PencereyiGizle ( btn:Button )

{
....
....
}

我对btn:Button

有疑问
  

1046:未找到类型或未找到类型   编译时常量:按钮..


package 
{
    import flash.display.MovieClip;
    import flash.display.NativeWindow;
    import flash.display.NativeWindowInitOptions;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.SimpleButton;


    public class PencereyiGizle extends MovieClip
    {
        public var natWindow:NativeWindow=new NativeWindow(
        new NativeWindowInitOptions());
        public var pencereyiAc_Btn:Button;

        public function PencereyiGizle(fro:Button)
        {
            pencereAc_Btn = fro;
            //Pencere ekleniyor
            natWindow.width = 500;
            natWindow.height = 400;
            natWindow.activate();
            natWindow.addEventListener(Event.CLOSING,pencereyiSakla);
            pencereyiAc_Btn.label = "Pencereyi Ac";
            pencereyiAc_Btn.addEventListener(MouseEvent.MOUSE_DOWN,pencereyiAktifEt);
        }
        //pencerenin kapanmasını engelleyip pencereyi gizliyoruz.;
        private function pencereyiSakla(e:Event):void
        {
            e.preventDefault();
            natWindow.visible = false;
        }

        //gizlenen pencereyi tekrar aktif hale getiriyoruz
        private function pencereyiAktifEt(e:MouseEvent):void
        {
            natWindow.activate();
        }
    }

}

N AIR;

import PencereyiGizle;

var firat:PencereyiGizle= new PencereyiGizle();
addChild(firat);

然后,我得到那个问题“1046:找不到类型或者不是编译时常量:按钮。”

我遇到了btn:Button

的问题

2 个答案:

答案 0 :(得分:0)

您应该使用import语句导入“按钮”

根据您的要求,它可以是

  1. Spark Button

    导入spark.components.Button;

  2. MX Button

    导入mx.controls.Button

  3. 更新:看起来this page可以回答您的问题。具体检查THIS回答

答案 1 :(得分:0)

你的问题是你的班级PencereyiGizle正在寻找一个按钮作为参考传递给你没有做的构造函数

var firat:PencereyiGizle= new PencereyiGizle();
addChild(firat);

您需要传递按钮的实例名称

var firat:PencereyiGizle= new PencereyiGizle( someButton );
addChild(firat);

或创建一个新按钮并将其传递给

var someButton:Button = new button
var firat:PencereyiGizle= new PencereyiGizle( someButton );
addChild(firat);