views:

31

answers:

3

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?

A: 

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.

jonathanasdf
+2  A: 

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

back2dos
That's right. It'll also work if you compile without strict mode -- which is not really recommended.
MrKishi
A: 

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

Daniel Hai