Thursday, January 20, 2005
I recently posted about a little Flash Video solution I built using PHPObject, I have decided to post the code for how I did it. First of all I built a service to open my flv directory and read the files. This consisted of a modified version of the PHP.net code example of how to read the contents of a directory. Basically it opens my '/flv' directory puts all the filenames into an array and then returns the array to Flash.
Now here is the actionscript used to tie it all together:
Let me explain what is happening here. First I import the PHPObject.as file set up the secret key and gateway links as per normal. Next I set up a new PHPObject which looks for a service called "myvideos", this contains the php code in the first example above. The following line sets up a responder function for the function getflvlist(), inside this responder I set the data provider of a comboBox component to an array which has been populated using a for loop with the contents of result (result being the array returned from m PHP service). Then I call the service function to populate the comboBox.
The next section simply sets up a listener object to, on change, concatenate a base URL with the filename which was returned by my PHP service and set as the value for the comboBox entries an then simply tell the media player component to play the file.
Now I just drop my FLV files in the flv directory and the comboBox instantly updates and is selectable.
Jon 9:08 PM Permalink
