In the Lynda.com title “ActionScript 3.0 in Flash CS3 Professional – Beyond the Basics” Todd Perkins shows how one way of typecasting
var xml: XML;
xml = event.target.data as XML
doesn’t work, while
var xml: XML;
xml = XML(event.target.data)
does. Shouldn’t both forms act the same way? How are they different?
TIA
Steven
edit
declarations added to the code
Basically they are different by
XML(event.target.data)meaning “cast this to that type” whereevent.target.data as XMLmeans “pretend it is XML”.The former is the same casting that you would expect in other languages like Java. It’s a useful way to have code not need to have a try-catch block around a cast. Using
aswill either return the the first operand if it is the correct type or null otherwise.You should take a look at the as operator if you need more information.