Why are objects still created when I omit importing classes in actionscript?
I'm working through a tutorial to create an mp3 player in actionscript. When I delete my first 4 lines of code, the .swf still works great! I thought you needed to declare what classes you're importing for every object you create later on.
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
//Objects and Variables
var myMusic:Sound= new Sound();
var soundFile:URLRequest = new URLRequest ("bobDylan.mp3");
var channel:SoundChannel = new SoundChannel();
//Listeners
btnPlay.addEventListener(MouseEvent.CLICK, playMusic);
btnStop.addEventListener(MouseEvent.CLICK, stopMusic);
function stopMusic(evt:MouseEvent):void{
channel.stop();
}
function playMusic(evt:MouseEvent):void
{
myMusic.l开发者_高级运维oad(soundFile);
channel = myMusic.play();
}
- Why are objects still created when I omit importing classes in actionscript?
- Also... What other than "classes" can you "import". Or can you only import classes?
It looks like you're working in the Flash IDE. If that is the case, then you can expect that it will be a good deal more forgiving than you would expect (or would like). Flash is probably importing the classes for you (check your publish settings and make sure they are on strict mode to force this issue). If it is, the objects being created are still the same objects you expect them to be, but don't trust it, fix the code.
The three things I've every imported are classes, functions (setTimeout, for example), and namespaces (mx_internal is used a lot in Flex).
精彩评论