I need to help about “ Action Script 3 , public Function with Button ”

守給你的承諾、 提交于 2020-01-07 04:33:25

问题


Public function PencereyiGizle ( btn:Button )

{
....
....
}

I have a problem with the btn:Button

1046: Type was not found or was not a compile-time constant:Button..


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);

and then, i get that problem "1046: Type was not found or was not a compile-time constant:Button. "

I have a problem with the btn:Button


回答1:


You should use the import statement to import "Button"

Depending on your requirements it could either be

  1. Spark Button

    import spark.components.Button;

  2. MX Button

    import mx.controls.Button

UPDATE: Looks like this page has an answer to your question. Specifically check THIS answer




回答2:


you problem is your class PencereyiGizle is looking for a button to be passed as a reference in the constructor which you are not doing

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

you need to pass either an instance name of a button

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

or create a new button and pass it along

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


来源:https://stackoverflow.com/questions/5766913/i-need-to-help-about-action-script-3-public-function-with-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!