THE PASZ.COM BLOG

Thursday, June 14, 2007

Some Ugly Flash Code

This code truly encapsulates some of the worst features of the ActionScript 2 APIs. Guess what it does...


var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
var stream_ns:NetStream = new NetStream(connection_nc);
video_1.attachVideo(stream_ns);
stream_ns.play("1.flv");
attachAudio(stream_ns);
var audio_sound:Sound = new Sound(this);
audio_sound.setVolume(0);


.
.
.
.
.
.
.
ANSWER: It loads an external FLV and mutes its volume.

Today, for the first time I had to do exactly that (in the past I always used a component, or embedded video). It seems pretty ridiculous that I have to instantiate 4 object -- NetConnection, NetStreem, Sound and a Video object you have to create in the library -- to achieve this basic goal. The documentation of these APIs is also pretty poor. I only figured out the muting part by scouring random message boards that Google coughed up. Yeesh!

I also had a lot of trouble getting this to work with MTASC. It looks like the best approach will be to create a standalone video playback module that I load into my main project.

If you need to deal with this stuff, I recommend this blog post, which has some good tidbits in the discussion.

30 Comments: