AS3错误#1007:在非构造函数上尝试实例化

时间:2011-04-25 12:39:17

标签: flash actionscript-3 typeerror

我在尝试创建库项目的实例时遇到标题错误:

trace(ApplicationSettings.AGEGATEVIEW);
var clazz:Class = ApplicationSettings.AGEGATEVIEW as Class;
ageGateForm = new clazz();

我的跟踪正确输出了类名,也就是库链接(即com.age.AgegateInputView)。我想我错过了一些明显的东西......

编辑:ApplicationSettings.AGEGATEVIEW引用的类:

package com
{
    import com.AgegateSubmitAgeEvent;
    import com.ButtonEvent;
    import com.LabelButton;
    import flash.text.TextFormat;
    import flash.events.FocusEvent;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.display.MovieClip;

    public class AgegateInputView extends MovieClip
    {
        protected var startColor         :uint = 0xCCCCCC;
        protected var textColor          :uint = 0x000000;
        protected var errorColor         :uint = 0xFF0000;

        protected var startFormat        :TextFormat;
        protected var textFormat         :TextFormat;
        protected var errorFormat        :TextFormat;

        protected var daySafe            :Boolean = false;
        protected var monthSafe          :Boolean = false;
        protected var yearSafe           :Boolean = false;


        public var dayInput              :TextField;
        public var monthInput            :TextField;
        public var yearInput             :TextField;

        public var submitBut             :LabelButton;

        public function AgegateInputView():void
        {
            startFormat = new TextFormat();
            startFormat.color = startColor;

            textFormat = new TextFormat();
            textFormat.color = textColor;

            errorFormat = new TextFormat();
            errorFormat.color = errorColor;

            if(stage) {
                init();
            } else {
                addEventListener(Event.ADDED_TO_STAGE,init);
            }
        }

        protected function setupInputs():void
        {
            dayInput.defaultTextFormat = startFormat;
            dayInput.text = "DD";
            dayInput.restrict = "0-9";
            dayInput.maxChars = 2;

            monthInput.defaultTextFormat = startFormat;
            monthInput.text = "MM";
            monthInput.restrict = "0-9";
            monthInput.maxChars = 2;

            yearInput.defaultTextFormat = startFormat;
            yearInput.text = "YYYY";
            yearInput.restrict = "0-9";
            yearInput.maxChars = 4;
        }

        protected function setupButton():void
        {
            submitBut.dispatchObj = {type:"age_submit"};
            submitBut.enabled = true;
        }

        protected function addListeners():void
        {
            dayInput.addEventListener(FocusEvent.FOCUS_IN, onInputFocus);
            dayInput.addEventListener(FocusEvent.FOCUS_OUT,checkDay);
            monthInput.addEventListener(FocusEvent.FOCUS_IN, onInputFocus);
            monthInput.addEventListener(FocusEvent.FOCUS_OUT,checkMonth);
            yearInput.addEventListener(FocusEvent.FOCUS_IN, onInputFocus);
            yearInput.addEventListener(FocusEvent.FOCUS_OUT,checkYear);
            submitBut.addEventListener(ButtonEvent.BUTTON_CLICK, onSubmit);
        }

        protected function removeListeners():void
        {
            dayInput.removeEventListener(FocusEvent.FOCUS_IN, onInputFocus);
            dayInput.removeEventListener(FocusEvent.FOCUS_OUT,checkDay);
            monthInput.removeEventListener(FocusEvent.FOCUS_IN, onInputFocus);
            monthInput.removeEventListener(FocusEvent.FOCUS_OUT,checkMonth);
            yearInput.removeEventListener(FocusEvent.FOCUS_IN, onInputFocus);
            yearInput.removeEventListener(FocusEvent.FOCUS_OUT,checkYear);
            submitBut.removeEventListener(ButtonEvent.BUTTON_CLICK, onSubmit);
        }

        protected function init(evt:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE,init);
            setupInputs();
            setupButton();
            addListeners();
        }

        protected function onInputFocus(evt:FocusEvent):void
        {
            var tf:TextField = evt.target as TextField;
            if(isNaN(Number(tf.text))) tf.text = "";
            tf.setTextFormat(textFormat);
            tf.defaultTextFormat = textFormat;
        }

        protected function checkDay(evt:FocusEvent):void
        {
            var value:Number = Number(dayInput.text);
            if(isNaN(value) || value < 1 || value > 31) {
                dayInput.setTextFormat(errorFormat);
                daySafe = false;
            } else {
                daySafe = true;
            }
        }

        protected function checkMonth(evt:FocusEvent):void
        {
            var value:Number = Number(monthInput.text);
            if(isNaN(value) || value < 1 || value > 12) {
                monthInput.setTextFormat(errorFormat);
                monthSafe = false;
            } else {
                monthSafe = true;
            }
        }

        protected function checkYear(evt:FocusEvent):void
        {
            var value:Number = Number(yearInput.text);
            var date:Date = new Date();
            if(isNaN(value) || value < 1900 || value > date.getFullYear()) {
                yearInput.setTextFormat(errorFormat);
                yearSafe = false;
            } else {
                yearSafe = true;
            }
        }

        protected function onSubmit(evt:ButtonEvent):void
        {
            evt.stopPropagation();
            if(daySafe && monthSafe && yearSafe) {
                dispatchEvent(new AgegateSubmitAgeEvent(AgegateSubmitAgeEvent.SUBMIT_AGE,{_day:dayInput.text, _month:monthInput.text, _year:yearInput.text}));
            }
        }
    }
}

所有公共属性都是组件舞台上的项目。在舞台上测试时,该组件工作正常,它只是动态附加它失败。

2 个答案:

答案 0 :(得分:0)

无论如何,在ApplicationSettings.AGEGATEVIEW类中,您是否尝试填充这样的数组:

new Array[1, 2, 3];

而不是正确的方式:

new Array(1, 2, 3);

答案 1 :(得分:0)

非常愚蠢,忘了使用getDefinition

var clazz:Class =  ApplicationDomain.currentDomain.getDefinition(ApplicationSettings.AGEGATEVIEW) as Class;