AS3 Error #1007: Instantiation attempted on a non-constructor
I'm getting the title error while trying to create an instance of a library item:
trace(ApplicationSettings.AGEGATEVIEW);
var clazz:Class = ApplicationSettings.AGEGATEVIEW as Class;
ageGateForm = new clazz();
My trace correctly outputs the class name that is also the library linkage (i.e. com.age.AgegateInputView). I think I'm missing something obvious...
Edit: The class that ApplicationSettings.AGEGATEVIEW refers to:
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";
开发者_StackOverflow中文版 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}));
}
}
}
}
All the public properties are items on the stage of the component. The component works fine when tested on the stage, it is just attaching it dynamically that fails.
by any chance, in your ApplicationSettings.AGEGATEVIEW class, are you attempting to populate an Array like this:
new Array[1, 2, 3];
instead of the correct way:
new Array(1, 2, 3);
Pretty stupid one really, forgot to use getDefinition
.
var clazz:Class = ApplicationDomain.currentDomain.getDefinition(ApplicationSettings.AGEGATEVIEW) as Class;
精彩评论