Explicitly typing variables causes compiler to think an instance of a builtin type doesn't have a property, which it does

StackOverflow https://stackoverflow.com/questions/2807790

Question

I narrowed the causes of an AS3 compiler error 1119 down to code that looks similar to this:

var test_inst:Number = 2.953;
trace(test_inst);
trace(test_inst.constructor);

I get the error "1119: Access of possibly undefined property constructor through a reference with static type Number."

Now if I omit the variable's type, I don't get that error:

var test_inst = 2.953;
trace(test_inst);
trace(test_inst.constructor);

it produces the expected output:

2.953
[class Number]

So what's the deal? I like explicitly typing variables, so is there any way to solve this error other than not providing the variable's type?

Was it helpful?

Solution

ok, this is a little hard to explain ... first of all, here is how it works:

var test_inst:Number = 2.953;
trace(test_inst);
trace((test_inst as Object).constructor);

to my understanding, this comes from the fact, that the property constructor comes from the ECMAScript-nature of ActionScript 3. It is an ECMAScript property of Object instances and is inherited through prototypes. From the strictly typed world of ActionScript 3 (which also uses a different inheritance mechanism), this property is thus not available.

greetz
back2dos

OTHER TIPS

http://www.kirupa.com/forum/showpost.php?p=1951137&postcount=214

that has all the info you need :)

basically, trace(test_inst["constructor"]) will work.

Object(someobject).constructor will achieve the same thing -- and you don't have to deal with compiler issues.

Object(someinst) === someclass works as well.

dh

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top