Lesson 6
null - undefined
In AS3 null and undefined are supposed to be different. While this issue was buggy in the beta 2 version it seems to be fixed now in the beta 3 version.
Null is when a variable has been declared but does not have any value. If a variable has not been declared then it is undefined and there will be a compiler error. Check also the examples in Starter_8.as for details. Play around and change parameters.
package
{
import flash.display.Sprite;
import flash.text.TextField;
public class Starter_7 extends Sprite
{
private var tField:TextField;
public function Starter_7 ()
{
myTest();
}
private function myTest():void
{
var a:Testvar = new Testvar ();
trace(a.test);
tField = new TextField();
if(a.test != null)
{
tField.text = "I am not null";
}
else
{
tField.text = "I am null";
}
addChild(tField);
}
}
}
//
import flash.display.Sprite;
class Testvar extends Sprite
{
public var test:String;
public function Testvar()
{
test = "I am a string";
}
}