package
{
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
public class EmbeddedSoundExample extends Sprite
{
[Embed(source="smallSound.mp3")]
public var soundClass:Class;
public function EmbeddedSoundExample()
{
//WHAT DOES "as" keyword DO IN THE FOLLOWING LINE ??
//*************************************************
var smallSound:Sound = new soundClass() as Sound;
//COULD BE WRITTEN AS :
//==>>>> var smallSound:Sound = new soundClass() ???
// OR
////==>>>> var smallSound:Sound = new Sound() ???
//******************************************************
smallSound.play();
}
}
}
答案 0 :(得分:5)
这是ActionScript 3中引入的转换运算符。与as
(与Type(object)
转换相反)的区别在于,如果转换失败,结果将是该类型的默认值。有关此here
答案 1 :(得分:1)
as
投射,使用您正在使用的类型等数据,不更改数据。
如果您使用Type(对象)并且无法转换为此Type,则返回默认值(null,zero或undefined)