2011-04-25 51 views
2

我得到標題錯誤,而試圖創建一個庫項目的實例:AS3錯誤#1007:實例化嘗試在非構造

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

所有的公共屬性都在組件的階段項目。在舞臺上進行測試時,該組件可以正常工作,只是動態地將其附加失敗。

+1

您能向我們展示ApplicationSettings.AGEGATEVIEW源代碼嗎? – 2011-04-25 13:14:10

+0

ApplicationSettings.AGEGATEVIEW是對類的字符串引用。我用代碼更新了我的問題。 – shanethehat 2011-04-25 14:08:18

回答

0

相當愚蠢的人真的,忘記使用getDefinition

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

任何機會,在你的ApplicationSettings.AGEGATEVIEW類,你要嘗試填充一個這樣的數組:

new Array[1, 2, 3]; 

,而不是正確的方法:

new Array(1, 2, 3); 
+0

順便說一句,如果你知道這些項目,最好的方法是'var a:Array = [1,2,3];' – alxx 2011-04-25 13:51:13