PDA

View Full Version : Can I reduce these 2 lines of code to 1 line?


ScottBlack80
12-21-2008, 08:06 PM
import scripts.ClassName;
var cn:ClassName = new ClassName();

CyanBlue
12-21-2008, 09:13 PM
Howdy and Welcome... :)

Well, you can simply remove a line break, but that does not really say it is a oneliner... ;)

What if you do this???
var cn:scripts.ClassName = new scripts.ClassName();

ScottBlack80
12-21-2008, 09:45 PM
I tried it, but it gave me these errors:

Type was not found or was not a compile-time constant: ClassName.
Access of undefined property scripts.

I thought import statements can be completely omitted, but maybe not.

CyanBlue
12-21-2008, 09:52 PM
You can do this...
//
var cn:flash.text.TextField = new flash.text.TextField();
cn.text = "Hello";
addChild(cn);
So, my guess is that 'scripts' is not in the directory where Flash's class scope...

ScottBlack80
12-22-2008, 12:18 AM
So, I guess an import statement is necessary in order to bring a user-defined package into Flash's scope