Flash and ASPPHP and JavaScript interaction

xiaoxiao2021-03-06  94

Hey, the first time I wrote the article, it is very nervous, this is the result of checking data on the Internet a few days ago, I hope to be useful to some friends. The horizontal limit, there is definitely wrong, the drums and high-end fingers are very grateful! Below, the book is positively transmitted: Flash has a classmate with JavaScript for intermediary and ASP / PHP, and the popularity is more popular. The previous time administrator trust me to write a HTML-based player on the class message, as required, it is to realize loop playback. So I wrote one, it is easier, nothing more than JavaScript operation and the interaction of the ActiveX control, checks MSDN to decide to use WMP's ActiveX plugin. After writing, the playback effect is always unreasonable. I don't know if I wrote JavaScript or WMP's JavaScript interface. There is a problem. Sometimes it is sometimes possible when playing. Later, I thought that Flash 7.0 can also play MP3, so I started design (I didn't learn system engineering so I didn't standard, I wouldn't laugh at generous): Goal: 1. Play MP3, basic play control function (pause, continue, index , Volume control, etc.); 2. Current track loop, list track loop implementation: 1. Musical list Dynamic retrieval from the database 2. Provide interface to add music URL here, my idea is: User Access ASP (PHP) page => ASP (PHP) Request Database => Return Data Set => ASP (PHP) Courses Data to JavaScript Variable => JavaScrit Write the DynamicText variable in Flash by flash interface => Flash will display this. One problem, the number of file list is unprepared, how to handle it in Flash, set a few variables? My solution is (maybe not a good way, but it is very simple. If the master has a better way, please let me know, thank you): Set two variables in Flash, one is saved file name varsongname another It is saved URL VARURL.

In the Server end, it is generated as (the English quotation marks herein is automatically replaced with Chinese quotation marks, please note): var strsongname = "SongName1, SongName2, SongName3"; variable definition / assignment statement of client JavaScript, then use The setvariable () statement incorporates this variable into the flash, Flash will set string split () into an array, then, don't teach it? Everyone is displayed. Under such ideas, 3 files have been born (SFMP means Simple Flash MP3 Player) 1) sfmp.swf - Flash file as a user interface; 2) sfmp.asp (.php) - request The database uses the file list as the HTML file returned by the Tarrable variable of JavaScript; 3) add.asp (.php) Add URL page. The procedure logic of each file is specifically explained, and the work step: sfmp.swf production

Since Flash MX 2004 Professional is used, many components are borrowed directly. (However, it should be cautious, because once the ActionScript 2.0 and the components are added, the file will increase, which will generally be more than 60 KB, depending on the use of the components. Specific reasons may include many set libraries?) Here is the components used inside: MediaPlayback Components: You can play MP3 directly. It includes many properties and methods, events. There is a more detailed description in Macromedia. InstanceName: _Player Action:

On (LOAD) {// You can insert some player initialization code} ON (Complete) {// This event generates // switching process if a music is played, resulting == true) {//// When a loop playing current track _Root._Player.Play ();} else {if (_root._cbloopall.selected == true) {// Select a loop play all list track var IindexRead: Number = _root.sonslist.selectedIndex; // Move a high bright strip in the list // If you have already arrived, reset the IIndexread ; if (IINDEXREAD> _ROOT.SONGSLIST.LENGTH - 1) {// set current Song index = 0 = 0 @ iDexread = 0;} // Update list display _root.songslist.selected "ot.songslist.selected; // Here, a function is called to get the playlist's currently selected URL / / and use setMedia () and play () methods to play the player play track // Due to the relatively simple }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} {// is playing music}}} {// When downloading music files} List component: The list of files used to retrieve from the database. InstanceName: SongSlist Action:

On (Change) {// Player Control // Get List Item Data Var Str: String = this.getItemt (this.selectedIndIndex) .data; if (str.Length> 0 && str! = undefined) {// Open THE URL _Root._Player.SetMedia (Str, "MP3"); if (_root._player.contentpath.length> 0) {_root._player.play ();}}} / * read the currently selected file from the list, get Its DATA (assuming that the required information has been read from the database, the Label display file name DATA is stored in the file URL) Since set the MediaPlayback component to AutoStart = FALSE, you need to run the play () method to start playing if AutoStart = True, once the ContentPath property is set, immediately load and play * / checkbox components: There are two, used to choose a single loop or a list loop. InstanceName: _cbloopCur, _cbloopall action: The two are mutually exclusive relationships, select one, cancel the other, two are not selected, the playback selection track is over, the code is simple, slightly. Dynamic Text Box: There are two, although not a component, but is the key to interacting with JavaScript. Variable: VarsongName, VARURL two variables are filenames and URLs that save the outside world, respectively. Tips: In JavaScript, Flash provides a lot of interface functions, which is used to set the setvariable (variable_name, value) function of the variable in Flash; Flash, a ActionScript function fscommand () is also provided with JavaScript interaction.

Sfmp.asp (PHP) file program logic: This program is very simple, I will not talk, directly post the code, if you don't understand, you can ask me, email contact.

<% 'This is some source code for sfmp.asp. After some modifications, it may contain some errors, because there is no test' Some environments may be different from the above machine, please modify accordingly.

'The complete source code before modifying is the test of the Windows98 PWS Access environment', so please check if there is no spelling or other obvious mistakes before use, thank you! Option Explicit Dim Rsfiles, CNN, STRSQL, STRCNN 'Using the ADO link database, obtains the data set, and there is no good speaking strCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN.4.0; Data Source = "& Server.mappath (" Songs. mdb ") Set cnn = Server.CreateObject (" ADODB.Connection ") cnn.Open strCnn strSql =" SELECT * FROM songsInfo WHERE type = 'mp3' ORDER BY id DESC "Set rsFiles = Server.CreateObject (" ADODB.RecordSet " Rsfiles.cursorlocation = 3 Rsfiles.open strsql, CNN, 2, 3 'Stop execution, stop execution, output error if typeename (RSFiles) = "nothing" the response.write ("Open Recordset Error
" ) Response.end () end if%> > If r s = "URL1, URL2, URL3"; this is the File name Strurl = rsfiles.fields ("Name") ' "URL") 'This is a URL RSFILES.MOVENEXT Do While Not Rsfiles.eof Strname = Strname & "& Rosfiles.Fields (" Name ") Strurl = Strurl &" & Replace (rsfiles.fields (" URL ") RSFI Les.Movenext loop endiff 输 output response.write ("VAR URL =" & Chr (34) & Strurl & Chr (34) & "; & Vbcrlf &" Var SongName = "& Chr (34) & Strname & Chr ( 34) & ";" & VBCRLF) 'Close the data set, release resources set rsfiles = Nothing cn.close () set cnn =

Nothing%> Myflashobj.Setvariable ("VARURL", Sound [INDEXREAD]); MyFlashobj.Setvariable ("VarsongName", Songname [IIndexread]); The above ASP code, in fact, sfmp.php is also very simple, linking database is replaced with mysql_connect / mysql_db_query / mysql_fetch_Object The corresponding function response.write () is replaced with ECHO. Since my PHP page is not used by JavaScript and Flash interaction (but below the way I will talk about directly, I don't have this code, I am embarrassed.

ADD.ASP (PHP) program logic:

This is more simple, you need a table and an ASP (PHP) code to get it: this is an HTML form, which is included in the Add.asp (PHP) file, its action is pointing to yourself.

name: link address:

This is the ASP code segment

<% 'This is part of Add.asp, after some modifications, it may contain some errors, because there is no test' Some environments may be different from your machine, please modify accordingly. 'The complete source code before modifying is the test of the Windows98 PWS Access environment', so please check if there is no spelling or other obvious mistakes before use, thank you! DIM STROUTPUT DIM STRNAMEOFSONG: STRNAMEOFSONG = Trim (Request.form ("Name")) DIM Strull: Strurl = Trim (Request.form ("URL")) 'Server.urlencode () IF Len (StrURL)> 0 Then' The legality check of the URL can be added, and StrCNN = "provike = microsoft.jet.oledb.4.0; data source =") set cnn = server.createObject ("adoDb.connection ") Cnn.open strcnn streli =" INSERT INTO SONGSIINFO (URL, NAME) VALUES ('"& strurl &",' "& strunameofsong &") "ISEMPTY (cnn.execute (strsql)) Then stroutPut =" Add data failed, Maybe the database has a problem, please contact the administrator, thank you! "Else stroutPut =" Add data success, you can continue to add, thank you! "End ifnd IF%> This is the PHP code snippet

0) {// ExecuteSQL () is a custom function, The role is to connect to the database, return mysql_db_query () $ RESULT $ IRESULT = ExecuteSQL ("INSERT INTO SONGSIINFO (URL, NAME) VALUES ('$ Strurl', '$ StrnameOfsong')"); if (! $ IRESULT) {$ Stroutput = "Appending failed Maybe some errors occured Please contact Admin Thanks for your support...!";} else {// successfully execute $ strOutput = "The file has successfully appended You can append another file now Thanks for your support..! "}}?> The above is the process of interacting with the ASP / PHP through javascript, please tell me any questions, thank you!

Flash and ASP / PHP direct interaction

FLASH is available directly as a client request ASP / PHP page. But I found a problem in a lot of related articles in this regard. When the ASP / PHP page returns a variable, if it is Chinese, then in Flash will become garbled (do not know other version will There will be this problem, but Flash 7.0 is this)! At that time, I thought that it might be a URL encoding, but I didn't find a solution. I suddenly thought of the issue of Unicode encoding? One check, I found out that the original Flash 7.0 encoding the external variable and the text is Unicode! The coding of ASP 3.0 is not, but the local encoding is used, so there is a problem. (ASP 3.0 I didn't find how to change the encoding method, asp.net seems to be default unicode, or use GB2312 encoding), so since there is no way to unify Unicode, you have to unify all Unified to GB2312. Checked Flash's reference, find a property that can be used to set the encoded, system.usecode = Ture; use local encoding when True is used, and use Unicode. Another point to pay attention, this property can only be set once at the beginning, if not, it may result in the unpredictable consequences (Flash refer to the above). Here, my idea is: flash request ASP / PHP page => ASP / PHP query database, return data directly to the flash variable => Flash display list

The loadvariableSnum () function is transmitted to the ASP / PHP, and the ASP / PHP can be used to obtain the variables in the Flash in Flash (which is specified in DynamicText) according to different request methods (POST / GET) (POST / GET). Form () / $ http_post_var () $ http_get_var (). The ASP / PHP returns easier, only returns such as VarsongName = SongName1, SongName2, SongName3 & VarURL = URL1, URL2, URL3 strings can be used, here there should be pay attention: 1. VarsongName and VarURL are Flash Variables, the name is the same, otherwise Flash can not resolve; 2. Do not output any other characters before outputting this string (HTTP headed can of course, because it is written to the html), anything, including < HTML tags such as HTML> . This will have 2 files, sfmp.htm - Due to no dynamic content, you can use a static page directly; RequestReciever.asp (PHP) - accept the request query database returns a string, sfmp.htm does not require special requirements, embed .swf file embedded It is okay, there is no place to post it. Let's post RequestReciever.asp (PHP) code:

RequestReciever.asp (PHP) code:

<% OPTION Explicit 'This is some source code of add.asp. After some modifications, it may contain some errors, because there is no test' There are some environments that may be different from your machine, please modify accordingly.

'The complete source code before modifying is the test of the Windows98 PWS Access environment', so please check if there is no spelling or other obvious mistakes before use, thank you! Dim rsFiles, strDisp, cnn, strSql, strCnn 'create and open a connection object strCnn = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" & Server.MapPath ( "songs.mdb") Set cnn = Server.CreateObject ( "ADODB.Connection") cnn.Open strCnn 'execute a SQL to create a RecordSet object strSql = "SELECT * FROM songsInfo WHERE type ='" & strAsk & " 'ORDER BY id DESC" Set rsFiles = Server.CreateObject ( "ADODB. ") Rsfiles.cursorlocation = 3 rsfiles.open strsql, cnn, 2,3 'ifeting object if Typename (Rsfiles) =" Nothing "Then Response.write (" Open Recordset Error
" ) Response.End () End If 'walkthrough the recordset and' prepare URL / POST variables strings Dim strName, strUrl If rsFiles.RecordCount> 0 Then strName = rsFiles.Fields ( "name") strUrl = rsFiles.Fields ( "url" ) Rsfiles.movenext do while not rsfiles.eof strname = strname & "," & rsfiles.fields ("name") StrURL = Strurl & "," & RSFiles.fields ("URL") rsfiles.movenext loop endiff ("songname =" & server.urlencode (strname) & "& url =" & strurl) 'Close THE Connection 'Release Resource Set Rsfiles = Nothing cnn.close () SET CNN = Nothing%> The following is the code of RequestReciever.php

'); } else {// walkthrough the recordset and // prepare URL / POST variables strings $ oRows = @ mysql_fetch_object ($ result); $ strName = $ oRows-> name; $ strUrl = $ oRows-> url; // response to client While ($ OROWS = @ mysql_fetch_object) {$ Strname. = "," $ OROWS-> Name; $ StrURL. = "," $ OOWS-> URL;} Echo "Songname =". $ STRNAME "& Url =". $ StrURL mysql_free_result ($ result);} // close the connection // Release resource mysql_close ($ ID_LINK);?> Ok, I have already written for several hours, really tired, have a problem Looking for me, thank you!

转载请注明原文地址:https://www.9cbs.com/read-96677.html

New Post(0)