|
Building The File (Pt 2)
Now it's time for the code that ties this all together.
Although the code isn't too complicated in itself you may find some of the steps a little unusual,
so hopefully the following analogy will help smooth the way and make it much easier to remember all the steps involved.
Let's say you live in a house with no cable TV (I can hear Americans skipping heartbeats already!).
So the cable people come and dig up the road and lay a cable connection right to your door - this is like the NetConnection class.
Multiple TV channels will be able to travel through this single connection.
Now you want to subscribe to a couple of film channels. Each channel is a bit like the NetStream class - you'll need one NetStream instance for each film you want to watch;
the channels all arrive via the same cable (NetConnection), yet each channel had its own schedule of films
(ie each channel can function independently of any other channel).
Finally, you have your TV (the instance of the video object we created earlier).
You'll need more than one TV if you want to watch more than one film simultaneously. Okay, it's not the best analogy, but it may help some of you.
So first, let's create the NetConnection:
7. var nc = new NetConnection();
All we are doing here is laying the cable, or rather, creating a new instance of the NetConnection class and calling it 'nc'.
Note: If you wish to use strict data typing you could have written:
var nc:NetConnection = new NetConnection();
but to keep these tutorials as accessible to as many people as possible I tend not use strict datatyping in them.
8. The workman have done a sterling job, although you do wish they hadn't started work at 7am.
The cable alone does nothing until the cable company hooks it up and supplies our house with some 'juice'.
This is effectively what the next line of code does, so add this below the first:
nc.connect(null);
The connect() method opens a local connection, through which we can play back video (FLV) files from an HTTP address or from the local
file system - but that sounds much more confusing than "supplying the juice"! Why are we passing a value of null?
Well, the Flash dictionary tells us that we must do this in order for it to work, and it doesn't give any more details than that!
|